why can't asp.net find my textbox?

Posted by phunehehe on Stack Overflow See other posts from Stack Overflow or by phunehehe
Published on 2010-05-05T12:35:58Z Indexed on 2010/05/05 12:38 UTC
Read the original article Hit count: 392

Hello,

I'm trying to add more fields to the CreateUserWizardStep, here is what I added:

<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>

Then I tried to reference the objects like this

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
}

The problem is, I'm getting nulls for nickName. Am I using FindControl("") incorrectly?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET