-1
<%@ Page Title="Register" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Register.aspx.cs" Inherits="dating.Account.Register" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:CreateUserWizard ID="RegisterUser" runat="server" EnableViewState="false" OnCreatedUser="RegisterUser_CreatedUser">
        <LayoutTemplate>
            <asp:PlaceHolder ID="wizardStepPlaceholder" runat="server"></asp:PlaceHolder>
            <asp:PlaceHolder ID="navigationPlaceholder" runat="server"></asp:PlaceHolder>
        </LayoutTemplate>
        <WizardSteps>
            <asp:CreateUserWizardStep ID="RegisterUserWizardStep" runat="server">
                <ContentTemplate>
                    <h2>
                        Skapa nytt konto
                    </h2>
                    <p>
                        Fyll i formulären nedan
                    </p>
                    <span class="failureNotification">
                        <asp:Literal ID="ErrorMessage" runat="server"></asp:Literal>
                    </span>
                    <asp:ValidationSummary ID="RegisterUserValidationSummary" runat="server" CssClass="failureNotification" 
                         ValidationGroup="RegisterUserValidationGroup"/>
                    <div class="accountInfo">
                        <fieldset class="register">
                            <legend>Kontoinformation</legend>
                            <p>
                                <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Användarnamn:</asp:Label>
                                <asp:TextBox ID="UserName" runat="server" CssClass="textEntry"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" 
                                     CssClass="failureNotification" ErrorMessage="Du måste fylla i användarnamn" ToolTip="User Name is required." 
                                     ValidationGroup="RegisterUserValidationGroup">*</asp:RequiredFieldValidator>
                            </p>
                        </fieldset>
                        <p class="submitButton">
                            <asp:Button ID="CreateUserButton" onclick="InsertUser" runat="server" CommandName="MoveNext" Text="Skapa användare" 
                                 ValidationGroup="RegisterUserValidationGroup"/>
                        </p>
                    </div>
                </ContentTemplate>
                <CustomNavigationTemplate>
                </CustomNavigationTemplate>
            </asp:CreateUserWizardStep>
        </WizardSteps>
    </asp:CreateUserWizard>
</asp:Content>

I'm trying to use the value from the textbox with ID UserName from code-behind, but this is not working:

UserName.Text
Oded
  • 489,969
  • 99
  • 883
  • 1,009
MrProgram
  • 5,044
  • 13
  • 58
  • 98
  • 7
    "but this is not working" is a terrible description. What isn't working? Errors? Exceptions? Something else? – Oded Jan 02 '13 at 11:03
  • What is Skapa nytt konto Fyll i formulären nedan Kontoinformation Användarnamn: * ? Please use english. – Soner Gönül Jan 02 '13 at 11:04
  • What do you mean by saying "this is not working"? Please give more detail on it. – ducnh Jan 02 '13 at 11:04
  • you can use FindControl("UserName") or something likeTextBox userNameTextBox = (TextBox)RegisterUserWizardStep.Controls(0).FindControl("UserName"); – MMK Jan 02 '13 at 11:07
  • Sorry for bad description, but I want the value from the textbox with ID UserName, but I can't find access to it from code-behind, and t doesn't work with using ID.Text – MrProgram Jan 02 '13 at 11:16
  • i fully understand that but basically it's impossible. – ducnh Jan 02 '13 at 11:23
  • So to be simple, i cant give you any advice with that description of error – ducnh Jan 02 '13 at 11:29
  • possible duplicate of [Findcontrol property not working in createUserWizard](http://stackoverflow.com/questions/13861442/findcontrol-property-not-working-in-createuserwizard) – Mike Perrenoud Jan 02 '13 at 11:31
  • Show us your code behind and where in the code your are trying to access the value because I can definitely access it? – Azhar Khorasany Jan 02 '13 at 11:43

2 Answers2

1

You can access the username by using [ID of the CreateUserWizard].UserName. The CreateUserWizard control exposes properties used to access values entered into the fields

 string username = RegisterUser.UserName;
 string email = RegisterUser.Email;
 ... etc

And you can also set it from code-behind

 RegisterUser.UserName = "John Doe";

Update: If you need to find the control, use

TextBox usernameTextBox = RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("UserName") as TextBox;
string username = usernameTextBox.Text;
codingbiz
  • 26,179
  • 8
  • 59
  • 96
0

You can use this one:

TextBox UserName = (TextBox)"StepNameHere".FindControl("UserName");

The control that you're accessing is currently not created on a event that you're using. I guess this will help.

roybalderama
  • 1,650
  • 21
  • 38