Reputation: 3797
I have created a simple CreateUserWizard to register my users. I've added 2 TextBox : LastName and FirstName.
Now, I would like to add them in my database when the user is registrated. Here is what I've done :
<asp:CreateUserWizard ID="RegisterUser" runat="server" EnableViewState="false" OnCreatedUser="RegisterUser_CreatedUser" RequireEmail="false">
<WizardSteps>
<asp:CreateUserWizardStep ID="RegisterUserWizardStep0" runat="server">
<ContentTemplate>
<asp:TextBox ID="LastName" runat="server" ></asp:TextBox>
[...]
<asp:Button ID="CreateUserButton" runat="server" CommandName="MoveNext" Text="S'inscrire"
ValidationGroup="RegisterUserValidationGroup"/>
And in the .cs file :
protected void RegisterUser_CreatedUser(object sender, EventArgs e)
{
TextBox test = RegisterUser.FindControl("LastName") as TextBox;
// Or using the generated ID
TextBox test2 = RegisterUser.FindControl("MainContent_RegisterUser_CreateUserStepContainer_LastName") as TextBox;
}
But whatever I try, my TextBox is always null
...
Did I miss something ? How could I get the value of these TextBox ?
Edit : This solution worked for me :
(TextBox)RegisterUser.WizardSteps[0].FindControl("CreateUserStepContainer").FindControl("LastName");
The only problem is I found the container name "CreateUserStepContainer" by using the debugger...
Upvotes: 4
Views: 1123
Reputation: 3797
This solution worked for me :
(TextBox)RegisterUser.WizardSteps[0].FindControl("CreateUserStepContainer").FindControl("LastName");
Upvotes: 2
Reputation: 17655
you have to find the control from CreateUserWizard.CreateUserWizardStep.ContentTemplateContainer.control
do like this:
TextBox test = (TextBox)RegisterUser.RegisterUserWizardStep0.ContentTemplateContainer.FindControl("LastName");
Upvotes: 1