你说的是遍历页面找TextBox的ID吗?? 这样可以: foreach (Control oControl in this.Controls) { if (oControl.GetType() == typeof(HtmlForm)) { foreach (Control item in oControl.Controls) { if (item.GetType() == typeof(TextBox)) { ((TextBox)item).ReadOnly = true; //得到所有的TextBox,设为只读 } } } }
通过reflector反编译看看控件属性, 遍历页面控件判断类型只是一种可能 foreach (Control control in this.Form.Controls) { if (control is System.Web.UI.WebControls.TextBox) { TextBox txt = (TextBox)control; } }
在设计窗口里选中这控件的时候旁边的属性他只会把textbox的ID显示出来怎么做到的?
这样可以: foreach (Control oControl in this.Controls)
{
if (oControl.GetType() == typeof(HtmlForm))
{
foreach (Control item in oControl.Controls)
{
if (item.GetType() == typeof(TextBox))
{
((TextBox)item).ReadOnly = true; //得到所有的TextBox,设为只读
}
}
}
}
遍历页面控件判断类型只是一种可能
foreach (Control control in this.Form.Controls)
{
if (control is System.Web.UI.WebControls.TextBox)
{ TextBox txt = (TextBox)control; }
}