我正在尝试向 CreateUserWizardStep
添加更多字段,这是我添加的内容:
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
<ContentTemplate>
<table border="0">
<tr>
<td align="right">
<asp:Label ID="NickNameLabel" runat="server" AssociatedControlID="NickName">Nick Name:</asp:Label>
</td>
<td>
<asp:TextBox ID="NickName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="NickName"
ErrorMessage="Nick Name is required." ToolTip="Nick Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<%-- The default code is left unchanged, but not shown here --%>
</table>
</ContentTemplate>
</asp:CreateUserWizardStep>
然后我尝试像这样引用对象
protected void NewUserWizard_CreatedUser(object sender, EventArgs e)
{
CreateUserWizardStep step = NewUserWizard.FindControl("CreateUserWizardStep1") as CreateUserWizardStep;
TextBox nickName = step.FindControl("NickName") as TextBox;
// insert additional information to the database
}
问题是,我得到的 nickName
为空。我是否错误地使用了 FindControl("")
?
最佳答案
您可能想使用递归查找控制函数,如下所示:http://stevesmithblog.com/blog/recursive-findcontrol/
关于c# - 为什么 ASP.NET 找不到我的文本框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2773176/