【发布时间】:2012-09-30 06:30:09
【问题描述】:
我是 ASP.NET 的新手,但一直给我带来麻烦的是查找嵌套的服务器控件,尤其是嵌套的服务器控件。
在这种情况下,这是我的注册页面,直到我想要的服务器控件:
<asp:CreateUserWizard runat="server" ID="RegisterUser" ViewStateMode="Disabled" OnCreatedUser="RegisterUser_CreatedUser">
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="wizardStepPlaceholder" />
<asp:PlaceHolder runat="server" ID="navigationPlaceholder" />
</LayoutTemplate>
<WizardSteps>
<asp:CreateUserWizardStep runat="server" ID="RegisterUserWizardStep">
<ContentTemplate>
<fieldset>
<ol>
<li>
<asp:TextBox runat="server" ID="firstName" />
</li>
为了便于阅读,我只删除了一些 HTML 元素。我正在尝试访问'firstName'。我已经尝试了以下所有方法,但没有成功,(TextBox first 总是为空)。
TextBox first = (TextBox)Page.Master.FindControl("MainContent").FindControl("firstName");
TextBox first = (TextBox)Page.FindControl("firstName");
TextBox first = (TextBox)RegisterUserWizardStep.FindControl("firstName");
TextBox first = (TextBox)RegisterUser.FindControl("firstName");
不胜感激,谢谢!
【问题讨论】:
-
我忘了添加我使用母版页的内容,以上所有内容都在占位符中。
标签: c# asp.net visual-studio