Why Can't I Reference a TextBox by ID When it's in a CreateUserWizard Control?

asp.net, code-behind, element

Solution

TextBox nameTextBox =
  CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Name") as TextBox;

if (nameTextBox != null) {
    /* Do your stuff */
}

More examples here.

Problem

I got a wierd problem here. Inside an asp.net CreateUserWizard, I got some elements, but I can't seem to access them from my code-behind. Here's a code snippet: Markup: ``` <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CreateUserWizard.ascx.cs" Inherits="Web.UserControls.CreateUserWizard" %> <asp:CreateUserWizard ID="CreateUserWizard1" runat="server" OnCreatingUser="CreatingUser"> <WizardSteps> <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server"> <ContentTemplate> <table border="0"> <tr> <td> <span class="requiredField"/> <asp:Label ID="NameLabel" runat="server" AssociatedControlID="NameRequiredFieldValidator">Navn:</asp:Label> <asp:CheckBox ID="ShareInfoCheckBox" runat="server" Checked="True" Text="Share my information with partner sites." /> </td> <td> <asp:TextBox ID="Name" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="NameRequiredFieldValidator" runat="server" ControlToValidate="Name" ErrorMessage="Du skal indtaste dit navn" ToolTip="Du skal indtaste dit navn" ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> </ContentTemplate> </asp:CreateUserWizardStep> </WizardSteps> </asp:CreateUserWizard> ``` .. And here's the codebehind: ``` public partial class CreateUserWizard : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { } protected void CreatingUser(object sender, EventArgs e) { Name. //no intellisense and compiler error when I try to access Name } } ``` Shouldn't this work? It's inside a UserControl if that makes any difference. Thanks in advance

Original source