应用了母板页后,由于层次多了,FindControl不能检索到深层的控件,所以要改为:
TextBox txt = (TextBox ) Page.PreviousPage .Form.FindControl
("ContentPlaceHolder1").FindControl("txtSearch");
Response.Write(txt.Text);
其实,在应用了母版页的页面里,即使Page.FindControl("txtSearch")都是不行的,必
须用Page.Form.FindControl("ContentPlaceHolder1").FindControl("txtSearch")
原来是这样的:
母版页里有一HtmlTable,ID为"tbWebAddress"),如果想在ASPX子页面使用tbWebAddress
的话,只要这样引用:
Dim WebAddress As HtmlTable = Page.Master.FindControl("tbWebAddress")
然后,使用WebAddress就象使用页面内的控件一样了.
TextBox txt = (TextBox ) Page.PreviousPage .Form.FindControl
("ContentPlaceHolder1").FindControl("txtSearch");
Response.Write(txt.Text);
其实,在应用了母版页的页面里,即使Page.FindControl("txtSearch")都是不行的,必
须用Page.Form.FindControl("ContentPlaceHolder1").FindControl("txtSearch")
原来是这样的:
母版页里有一HtmlTable,ID为"tbWebAddress"),如果想在ASPX子页面使用tbWebAddress
的话,只要这样引用:
Dim WebAddress As HtmlTable = Page.Master.FindControl("tbWebAddress")
然后,使用WebAddress就象使用页面内的控件一样了.
另外,如果使用了诸如Repeater等动态邦定数据的控件,如果想知道该控件中某个子控件的确切id可以使用它的ClientID属性。