它可能在任何一個Control.要仔細找.
Page.Controls
-System.Web.UI.HtmlControls.HtmlForm.Controls
---System.Web.UI.WebControls.Panel.Controls
----System.Web.UI.WebControls.TextBox
void Clear()
{
foreach (object ctrl in Page.Controls)
{
if (ctrl is System.Web.UI.HtmlControls.HtmlForm)
{
System.Web.UI.HtmlControls.HtmlForm form = (System.Web.UI.HtmlControls.HtmlForm)ctrl;
foreach (object p in form.Controls)
{
if (p is System.Web.UI.WebControls.Panel)
{
System.Web.UI.WebControls.Panel _Panel = (System.Web.UI.WebControls.Panel)p;
foreach (object y in _Panel.Controls)
{
if (y is System.Web.UI.WebControls.TextBox)
{
((TextBox)y).Text="";
}
if (y is System.Web.UI.WebControls.DropDownList)
{
string str_key = ((DropDownList)y).ID.Substring(0, 7);
if (str_key == "ddlxxxx")
{
((DropDownList)y).SelectedValue = "1";//預設1
}
}
}
}
}
}
}
}
ref
https://dotblogs.com.tw/dotjum/2008/04/19/2952