silvdb silvdb - 8 months ago 60
ASP.NET (C#) Question

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"
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server"
Title="Registreer uw organisatie">
<div class="row">
<div class="half">
<td align="right">
<asp:Label ID="lbl_organisation_description" runat="server" AssociatedControlID="txt_desc">Beschrijf uw organisatie:</asp:Label>
<asp:TextBox ID="txt_desc" runat="server" ValidationGroup="CreateUserWizard1"></asp:TextBox>

 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");