我在某处的堆栈溢出中找到了这些指令……我只添加了最后一个循环来查找我感兴趣的唯一对象,即文本框和下拉列表……对于找到的对象,我需要将 ReadOnly 属性从 true 更改为 false 或反之反之亦然...我无法确定如何定义受影响对象的对象名称...
在此先感谢您的帮助。
foreach (Control ctlMaster in Page.Controls)
{
if (ctlMaster is MasterPage)
{
foreach (Control ctlForm in ctlMaster.Controls)
{
if (ctlForm is HtmlForm)
{
foreach (Control ctlContent in ctlForm.Controls)
{
if (ctlContent is ContentPlaceHolder)
{
foreach (Control ctlChild in ctlContent.Controls)
{
if (ctlChild is Panel)
{
foreach (Control ctlform in ctlChild.Controls)
{
if (!string.IsNullOrEmpty(ctlform.ID))
{
Debug.WriteLine("ID = [" + ctlform.ID + "]");
Debug.WriteLine("UniqueID = [" + ctlform.UniqueID + "]");
Debug.WriteLine("type = [" + ctlform.GetType() + "]");
if(ctlform.GetType().ToString().IndexOf("TextBox") != 0
|| ctlform.GetType().ToString().IndexOf("DropDownList") != 0)
{
// **??? objectName.ReadOnly = true; ???**
}
}
}
}
}
}
}
}
}
}
}