Search code examples
c#asp.netcreateuserwizard

Findcontrol property not working in createUserWizard


I'm using ASP's createUserWizard control to create my users, and I'd like to add some extra fields (with extra info on the user) which I'm saving in my own table.

I try to access these custom textboxes in code behind with the findContol property (since they're inside the createUserWizard)

The problem is that the textbox I declare and initialize as the control, is null. Here's how I do it:

TextBox t_desc = (TextBox)(CreateUserWizard1.FindControl("txt_desc")); 
o.organisation_description = t_desc.Text;

And this is how the control is nested:

<asp:CreateUserWizard ID="CreateUserWizard1" runat="server"     
      oncreateduser="CreateUserWizard1_CreatedUser">
   <WizardSteps>
       <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server" 
                    Title="Registreer uw organisatie">
         <ContentTemplate>
            <div class="row">
               <div class="half">
                  <table>
                     <tr>
                        <td align="right">
                           <asp:Label ID="lbl_organisation_description" runat="server" AssociatedControlID="txt_desc">Beschrijf uw organisatie:</asp:Label>
                        </td>
                        <td>
                           <asp:TextBox ID="txt_desc" runat="server" ValidationGroup="CreateUserWizard1"></asp:TextBox>
                        </td>
                      </tr>
                    </table>
                  </div>
                </div>
              </ContentTemplate>
              </asp:CreateUserWizardStep>
          </WizardSteps>
</asp:CreateUserWizard>

Solution

  •  CreateUserWizardStep step =   (CreateUserWizardStep)  CreateUserWizard1.FindControl("CreateUserWizardStep1"); 
     if (step!=null)
     {
         TextBox txt =  (TextBox)step.ContentTemplateContainer.FindControl("txt_desc");
     }
    

    or if you can see your step control from server-code

    TextBox txt =  (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txt_desc");