[ASPX] 尋找Page下的Control 透過 foreach 方式
之前回答於
http://forums.microsoft.com/msdn-cht/ShowPost.aspx?PostID=765725&SiteID=14
void ClearTextBoxes() { 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 subctrl in form.Controls) { if (subctrl is System.Web.UI.WebControls.TextBox) { TextBox textctrl = (TextBox)subctrl; textctrl.Text = ""; } } } }
//特別要注意的是 Html 裡面不要設定到 runat="server" 這樣的會尋找範圍
就要在 System.Web.UI.WebControls.Table 下
剛好今天COPY另一個Html table 過來沒有注意到多弄了這段。
<table background="ballot_bk1.GIF" border="0" runat="server" cellpadding="0" cellspacing="0" style="width: 500px; height: 600px">