c# - 为什么 ASP.NET 找不到我的文本框?

标签 c# asp.net web-controls

我正在尝试向 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/

相关文章:

c# - 部署后NServiceBus反序列化异常

c# - ASP.NET Core + IIS Express 如何设置 SSL 证书

c# - 中继器链接按钮 Onclick 未触发

c# - ASP.NET Identity 中的零星应用程序死锁

asp.net - 使用linq获取网页中某种类型的Web控件列表

c# - 多行有多个提交按钮,我应该为每个按钮制作一个表单吗?

c# - ExecuteSqlInterpolated/ExecuteSqlRaw 参数在 asp.net core 中错误地传递到数据库

c# - 在 C# 中从中心开始裁剪图像

asp.net - 如何使我的 ASP.NET 服务器控件将嵌入的代码块作为属性值?

c# - Awesomium 网页控制