Why can't asp.net find the textbox?

I am trying to add more fields to CreateUserWizardStep

, this 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 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 am getting nulls for nickName

. Am I using wrong FindControl("")

?

+2


a source to share


3 answers


you can use recursive search function like here: http://stevesmithblog.com/blog/recursive-findcontrol/



+3


a source


FindControl

only

Searches for the current name container for the specified server control.

i.e. It checks the current containers directly for children.



You can use a property Controls

to return all child elements step

:

ControlCollection children = step.Controls;

      

and list this textbox search.

+2


a source


I don't know the control myself, but CreateUserWizardStep1.NickNameLabel doesn't work?

0


a source







All Articles