您的位置:首页 > 编程语言 > ASP

asp.net找控件

2013-12-20 17:02 357 查看
protected void Page_Load(object sender, EventArgs e)
{
/* 找到所有控件
Response.Write("Page_Load<br/>");
string str = "";
foreach (Control item in Page.Controls)
{
str+=item.GetType() + "  " + item.ID + "<br/>";
}
Response.Write(str);
* */
//找到LiteralControl控件的text内容。
/*
foreach (Control item in Page.Controls)
{
if (item is LiteralControl)
{
Response.Write(((LiteralControl)item).Text);
}
}*/
//递归遍历 可以找到控件里面的控件
GetContent(Page.Controls);
}
protected void GetContent(ControlCollection controls)
{
foreach (Control item in controls)
{
Response.Write(item.ToString() + "-----<br/>");
if (item.Controls!=null)
{
GetContent(item.Controls);
}
}
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: