.Net 环境下,有母版网页中的控件遍历
来源:互联网 发布:seo是什么意思 编辑:程序博客网 时间:2024/06/03 12:41
好久不写代码了,今天正好需要写一代码,遍历网上的控件,本以很简单,就写了以下这一段。
foreach (Control ctl in this.Page.Controls)
{
foreach (Control childctl in ctl.Controls)
{
((TextBox)childctl).Text = "";
}
}
但一测试,不行 。后来查了一下,这个页面加载了母版页,查了网上的写法,但不清楚。故自已写了一下,测试通过。
foreach (Control ctl in this.Page.Master.FindControl("MainContent").Controls)
{
if (ctl is TextBox)
{
((TextBox)ctl).Text = "";
}
}
由于这个项目中多处用到这个方法,故封装了一下。
public void OperControl(object obj)
{
foreach (Control ctl in ((Page)obj).Master.FindControl("MainContent").Controls)
{
if (ctl is TextBox)
{
((TextBox)ctl).Text = "";
}
}
}
同时,把使递归方法的代码一并贴上。
public void TraversalControl(ControlCollection ctlCl)
{
foreach (Control ctl in ctlCl)
{
if (ctl.HasControls())
{
TraversalControl(ctl.Controls);
}
else
{
if(ctl is TextBox)
{
//
}
else if (ctl is Label)
{
//
}
}
}
}
- .Net 环境下,有母版网页中的控件遍历
- asp.net 内容页访问母版页中的控件
- asp.net 在使用母版页的子页面cs后台代码中控制母版页中的登录控件显示
- ASP.NET中的母版页
- Asp.net中的母版页
- ASP.NET中的母版页
- 嵌套母版页中访问顶级母版页中的控件
- ASP.Net控件母版页专题
- ASP.NET 子页找母版页控件
- 遍历网页中所有的控件(asp.net)
- 嵌套母版页中的控件访问
- 如何访问嵌套母版页中的控件
- 嵌套母版页中的控件访问
- ASP.NET 2.0 中的母版页详解
- ASP.NET 2.0 中的创建母版页
- ASP.NET 2.0 中的母版页详解
- ASP.NET 2.0 中的创建母版页
- ASP.NET 2.0 中的母版页
- leetcode刷题日记—— Linked List Cycle II
- Qwt中的鼠标操作之缩放、平移
- 解决视网膜屏上看网页图片模糊的问题?
- 【虫师--系列】LR有的JMeter也有之三“集合点”
- 任性走通在线教育之路——如鹏创业一年总结
- .Net 环境下,有母版网页中的控件遍历
- iOS UIWebView
- 【虫师--系列】一种简单的数据库性能测试方法
- android gradle 多渠道打包分发
- 不包含特定字符串的匹配
- nyoj465 最大值和最小值
- java.lang.UnsupportedOperationException异常解决办法
- ArcGIS Server Open data output support GeoJSON
- 【虫师--系列】JMeter 聚合报告之 90% Line 参数说明