我有像TextBox这样的子元素的内容:
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">`<asp:TextBox ID="UserName" runat="server"></asp:TextBox>`</asp:Content>`
我尝试按如下方式找到此TextBox:
ContentPlaceHolder contentPlaceHolder;TextBox textBox1;
contentPlaceHolder = (ContentPlaceHolder)Master.FindControl("MainContent");
if (contentPlaceHolder != null){
textBox1 = (TextBox)contentPlaceHolder.FindControl("UserName");
if (textBox1 != null)
{`UserName = textBox1.Text;
}
}
但textBox1为null。无法找到。任何人都知道如何找到控件?也许我错了?谢谢:)。