普通页面、套用母版页的页面遍历TextBox控件的方法

xiaoxiao2023-02-02  29

1.普通页面遍历TextBox控件清空的方法,其他控件类似

foreach (Control col in this.Controls) { //if (col.GetType().Name.Equals("TextBox")) if (col is TextBox) { ((TextBox)col).Text = ""; } }

         

2.套用母版页的页面遍历TextBox控件的方法,其他控件类似

foreach (Control cp in Page.Controls) { foreach (Control ct in cp.Controls) { if (ct is HtmlForm) { foreach (Control con in ct.Controls) { foreach (Control c in con.Controls) { if (c is TextBox) { (c as TextBox).Text = ""; } } } } } }

 

备注:在很多情况下,虽然利用母版本比较方便,但也有弊端,如数据的重复加载(实际开发中用缓存解决),控件id号的改变(利用<%控件ID.客户端ID %>解决),类似如上的问题等。所以大家在实际开发中若感觉一种方法明明是对的,但就是得不到想要的结果,可以考虑下是不是母版的原因造成

本文来自博客,转载请标明出处:http://blog.csdn.net/fuhuiping/archive/2009/07/01/4312350.aspx

相关资源:引用母版页后在page页面修改母版页控件的值的方法
转载请注明原文地址: https://www.6miu.com/read-4981071.html

最新回复(0)