-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>

我正在尝试使用来自代码隐藏 ID UserName 的文本框中的值,但这不起作用:

UserName.Text
4

2 回答 2

1

您可以使用 访问用户名[ID of the CreateUserWizard].UserName。该CreateUserWizard控件公开用于访问输入到字段中的值的属性

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

你也可以从代码隐藏中设置它

 RegisterUser.UserName = "John Doe";

更新:如果您需要找到控件,请使用

TextBox usernameTextBox = RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("UserName") as TextBox;
string username = usernameTextBox.Text;
于 2013-01-02T11:10:56.770 回答
0

你可以使用这个:

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

您正在访问的控件当前不是在您正在使用的事件上创建的。我想这会有所帮助。

于 2013-01-02T11:12:02.350 回答