使用ASP.Net Membership和CreateUserWizard,我注意到我无法在代码中检索Passoword,UserName,ConfirmPassword等的值。我能够解除扩展的扩展属性。
想知道是否可以检索UserName等。我在下面提供了示例代码。当填写和回发字段时,我可以引用密码,ConfirmPassword,电子邮件和用户名,但收到的值是空字符串。我能够达到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在所有三个事件中都返回一个空字符串。为什么是这样?我该如何检索这些值?
答案 0 :(得分:0)
尝试通过OnCreatedUser事件获得相同的结果。