title: Controls does not exist in current context in ASP.Net CreateUserWizard
body: <p>I am working on a project in Microsoft Visual Studio using an ASP.NET web application with code behind in C#.  I added a CreateUserWizard and customized the form in step 1.  From the events handler I put a CreatedUser handler into the codebehind to update database tables.
  I want to pull the data values for the handler from the form, but the codebehind file can't see them for some reason.  Help!</p>
  
  <p>Main Page</p>
  
  <pre><code>&lt;asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="PageControls" runat="server"&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content3" ContentPlaceHolderID="RightBox" runat="server"&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content4" ContentPlaceHolderID="SiteControl1" runat="server"&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content5" ContentPlaceHolderID="SiteControl2" runat="server"&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content6" ContentPlaceHolderID="SiteControl3" runat="server"&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content7" ContentPlaceHolderID="CPMain" runat="server"&gt;
      &lt;center&gt;
          &lt;asp:CreateUserWizard ID="CreateUserWizard1" runat="server" 
  CreateUserButtonText="Submit"
              RequireEmail="False" OnCreatedUser="CreateUserWizard1_CreatedUser"&gt;
              &lt;WizardSteps&gt;
                  &lt;asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server"&gt;
                      &lt;ContentTemplate&gt;
                          &lt;table border="0" style="font-size: 100%"&gt;
                              &lt;tr&gt;
                                  &lt;td align="center" colspan="2" style="font-weight: 
  bold; color: white; background-color: #5d7b9d"&gt;
                                      Register with Acme!
                                  &lt;/td&gt;
                              &lt;/tr&gt;
                              &lt;tr&gt;
                                  &lt;td align="right"&gt;
                                      &lt;asp:Label ID="Label1" runat="server" 
  AssociatedControlID="UserName"&gt;
                          First Name:&lt;/asp:Label&gt;
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      &lt;asp:TextBox ID="FName" runat="server"&gt;
  &lt;/asp:TextBox&gt;
                                      &lt;asp:RequiredFieldValidator 
  ID="RequiredFieldValidator1" runat="server" ControlToValidate="FirstName"
                                          ErrorMessage="First Name is required." 
  ToolTip="First Name is required." ValidationGroup="CreateUserWizard1"&gt;*
  &lt;/asp:RequiredFieldValidator&gt;
                                  &lt;/td&gt;
                                  &lt;tr&gt;
                                      &lt;td align="right"&gt;
                                          &lt;asp:Label ID="Label2" runat="server"&gt;
                          Last Name:&lt;/asp:Label&gt;
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;asp:TextBox ID="LName" runat="server"&gt;
  &lt;/asp:TextBox&gt;
                                          &lt;asp:RequiredFieldValidator 
  ID="RequiredFieldValidator2" runat="server" ControlToValidate="LastName"
                                              ErrorMessage="Last Name is required." 
  ToolTip="Last Name is required." ValidationGroup="CreateUserWizard1"&gt;*
  &lt;/asp:RequiredFieldValidator&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td align="right"&gt;
                                          &lt;asp:Label ID="UserNameLabel" runat="server" 
  AssociatedControlID="UserName"&gt;
                          User Name:&lt;/asp:Label&gt;
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;asp:TextBox ID="UserName" runat="server"&gt;
  &lt;/asp:TextBox&gt;
                                          &lt;asp:RequiredFieldValidator 
  ID="UserNameRequired" runat="server" ControlToValidate="UserName"
                                              ErrorMessage="User Name is required." 
  ToolTip="User Name is required." ValidationGroup="CreateUserWizard1"&gt;*
  &lt;/asp:RequiredFieldValidator&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td align="right"&gt;
                                          &lt;asp:Label ID="PasswordLabel" runat="server" 
  AssociatedControlID="Password"&gt;
                          Password:&lt;/asp:Label&gt;
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;asp:TextBox ID="Password" runat="server" 
  TextMode="Password"&gt;&lt;/asp:TextBox&gt;
                                          &lt;asp:RequiredFieldValidator 
  ID="PasswordRequired" runat="server" ControlToValidate="Password"
                                              ErrorMessage="Password is required." 
  ToolTip="Password is required." ValidationGroup="CreateUserWizard1"&gt;*
  &lt;/asp:RequiredFieldValidator&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td align="right"&gt;
                                          &lt;asp:Label ID="ConfirmPasswordLabel" 
  runat="server" AssociatedControlID="ConfirmPassword"&gt;
                          Confirm Password:&lt;/asp:Label&gt;
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;asp:TextBox ID="ConfirmPassword" 
  runat="server" TextMode="Password"&gt;&lt;/asp:TextBox&gt;
                                          &lt;asp:RequiredFieldValidator 
  ID="ConfirmPasswordRequired" runat="server" ControlToValidate="ConfirmPassword"
                                              ErrorMessage="Confirm Password is 
  required." ToolTip="Confirm Password is required."
                                              ValidationGroup="CreateUserWizard1"&gt;*
  &lt;/asp:RequiredFieldValidator&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td align="center" colspan="2"&gt;
                                          &lt;asp:CompareValidator ID="PasswordCompare" 
  runat="server" ControlToCompare="Password"
                                              ControlToValidate="ConfirmPassword" 
  Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."
                                              ValidationGroup="CreateUserWizard1"&gt;
  &lt;/asp:CompareValidator&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td align="center" colspan="2" style="color: red"&gt;
                                          &lt;asp:Literal ID="ErrorMessage" runat="server" 
  EnableViewState="False"&gt;&lt;/asp:Literal&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td align="right"&gt;
                                          &lt;asp:Label ID="Label3" runat="server" 
  AssociatedControlID="UserName"&gt;
                          Role:&lt;/asp:Label&gt;
                                      &lt;/td&gt;
                                      &lt;td&gt;
                                          &lt;asp:DropDownList ID="RoleSelector" 
  runat="server"&gt;
                                              &lt;asp:ListItem 
  Value="Visitor"&gt;Visitor&lt;/asp:ListItem&gt;
                                              &lt;asp:ListItem 
  Value="Employee"&gt;Employee&lt;/asp:ListItem&gt;
                                              &lt;asp:ListItem Value="PM"&gt;Project 
  Manager&lt;/asp:ListItem&gt;
                                              &lt;asp:ListItem Value="DM"&gt;Department 
  Manager&lt;/asp:ListItem&gt;
                                              &lt;asp:ListItem Value="Director"&gt;IT 
  Director&lt;/asp:ListItem&gt;
                                          &lt;/asp:DropDownList&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                          &lt;/table&gt;
                      &lt;/ContentTemplate&gt;
                  &lt;/asp:CreateUserWizardStep&gt;
                  &lt;asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server"&gt;
                      &lt;ContentTemplate&gt;
                      &lt;/ContentTemplate&gt;
                  &lt;/asp:CompleteWizardStep&gt;
              &lt;/WizardSteps&gt;
          &lt;/asp:CreateUserWizard&gt;
      &lt;/center&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>CodeBehind:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Security.Principal;
  
  namespace Acme
  {
      public partial class Register : System.Web.UI.Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {
  
          }
  
          public void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
          {
              RolesManager.InsertEmployee(FName.Text, LName.Text, RoleSelector.Value, 
  User.Identity);
          }
      }
  }
  </code></pre>
  
  <p>I get these errors at compile time:</p>
  
  <pre><code>Error   1   The name 'FName' does not exist in the current context  C:\MV_Training\Jan2013\C#Projects\AcmePresentation\AcmePresentation\Register.aspx.cs    20  41  AcmePresentation
  Error   2   The name 'LName' does not exist in the current context  C:\MV_Training\Jan2013\C#Projects\AcmePresentation\AcmePresentation\Register.aspx.cs    20  53  AcmePresentation
  Error   3   The name 'RoleSelector' does not exist in the current context   C:\MV_Training\Jan2013\C#Projects\AcmePresentation\AcmePresentation\Register.aspx.cs    20  65  AcmePresentation
  </code></pre>
  
  <p>and this from the browser:</p>
  
  <p>Compilation Error
  Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.</p>
  
  <p>Compiler Error Message: CS1061: 'ASP.register_aspx' does not contain a definition for 'CreateUserWizard1_CreatedUser' and no extension method 'CreateUserWizard1_CreatedUser' accepting a first argument of type 'ASP.register_aspx' could be found (are you missing a using directive or an assembly reference?)</p>
  
  <p>Source Error:</p>
  
  <pre><code>Line 16: &lt;asp:Content ID="Content7" ContentPlaceHolderID="CPMain" runat="server"&gt;
  Line 17:     &lt;center&gt;
  Line 18:         &lt;asp:CreateUserWizard ID="CreateUserWizard1" runat="server" 
  Line 19:             CreateUserButtonText="Submit" RequireEmail="False" 
  Line 20:             oncreateduser="CreateUserWizard1_CreatedUser"&gt;
  </code></pre>
  
  <p>Source File: c:\MV_Training\Jan2013\C#Projects\AcmePresentation\AcmePresentation\Register.aspx    Line: 18</p>
  
  <p>Thanks,
  Bill</p>