0

使用 ASP.Net Membership 和 CreateUserWizard,我注意到我无法在代码中检索 Passoword、UserName、ConfirmPassword 等的值。我能够检索扩展的扩展属性。

想知道是否可以检索用户名等。我在下面包含了示例代码。填写字段并回发后,我可以引用 Password、ConfirmPassword、Email 和 UserName,但收到的值是空字符串。我能够达到 Title 字段的值,Title 字段返回空字符串。下面的代码只是一个子集。

<asp:CreateUserWizard ID="UserRegistration" runat="server" 
        onload="UserRegistration_Load" onprerender="UserRegistration_PreRender">
        <WizardSteps>
            <asp:CreateUserWizardStep ID="UserRegistrationStep_1" runat="server">
            <ContentTemplate>

                <asp:Label ID="lblUserName" runat="server" Text="User Name"></asp:Label>
                <asp:TextBox ID="UserName" runat="server"></asp:TextBox>
                <asp:Label ID="lblEMail" runat="server" Text="EMail"></asp:Label>
                <asp:TextBox ID="EMail" runat="server"></asp:TextBox>
                <asp:Label ID="lblPassword" runat="server" Text="Password"></asp:Label>
                <asp:TextBox ID="Password" runat="server"></asp:TextBox>
                <asp:Label ID="lblConfirmPassowrd" runat="server" Text="Confirm Password"></asp:Label>
                <asp:TextBox ID="ConfirmPassowrd" Text="1234567" runat="server"></asp:TextBox>
                <asp:Label ID="lblTitle" runat="server" Text="Title"></asp:Label>
                <asp:TextBox ID="Title" Text="Title1234567" runat="server"></asp:TextBox>
                <asp:PlaceHolder ID="Captcha" runat="server" />
            </ContentTemplate>
            </asp:CreateUserWizardStep>
            <asp:CompleteWizardStep ID="UserRegistrationStep_2" runat="server">
            </asp:CompleteWizardStep>

        </WizardSteps>
    </asp:CreateUserWizard>

我将示例代码放在三个不同的事件中:

   protected void Page_Load(object sender, EventArgs e)
    {
        string s0 = ((TextBox)UserRegistration.CreateUserStep.ContentTemplateContainer.FindControl("Password")).Text;
        string s1 = ((TextBox)UserRegistration.CreateUserStep.ContentTemplateContainer.FindControl("Title")).Text;
        string s2 = ((TextBox)UserRegistration.CreateUserStep.ContentTemplateContainer.FindControl("UserName")).Text;
        string s = s0+ s1 + s2;
    }

    protected void UserRegistration_Load(object sender, EventArgs e)
    {
        string s0 = ((TextBox)UserRegistration.CreateUserStep.ContentTemplateContainer.FindControl("Password")).Text;
        string s1 = ((TextBox)UserRegistration.CreateUserStep.ContentTemplateContainer.FindControl("Title")).Text;
        string s2 = ((TextBox)UserRegistration.CreateUserStep.ContentTemplateContainer.FindControl("UserName")).Text;
        string s = s0 + s1 + s2;
    }

    protected void UserRegistration_PreRender(object sender, EventArgs e)
    {
        string s0 = ((TextBox)UserRegistration.CreateUserStep.ContentTemplateContainer.FindControl("Password")).Text;
        string s1 = ((TextBox)UserRegistration.CreateUserStep.ContentTemplateContainer.FindControl("Title")).Text;
        string s2 = ((TextBox)UserRegistration.CreateUserStep.ContentTemplateContainer.FindControl("UserName")).Text;
        string s = s0 + s1 + s2;
    }

我可以在 Page_Load 事件中检索 Title 属性,但是 UserName 和 Password 在所有三个事件中都返回一个空字符串。为什么是这样?如何检索这些值?

4

1 回答 1

0

尝试通过 OnCreatedUser 事件获得相同的结果。

于 2012-02-27T01:41:49.240 回答