사용자는 표준 SQLMemberShipProvider로 작성됩니다.Codebehind에서 오류 메시지를 설정하는 방법 (TemplateLayout을 사용하여 CreateUserWizard 컨트롤)?
예외를 비롯하여 MembershipCreationStatus를 잡아 봤는데 코드를 디버깅 할 때 메시지를 설정하는 메서드가 생깁니다. CreateUserWizardControl의 속성을 사용하여 설정하지만 페이지가 렌더링 될 때 기본값이 표시됩니다. 방금 설정 한 (맞춤) 메시지가 아닙니다.
내가 작업하고있는 마법사는 한 걸음 만 내딛었지만 실제로 잘못된 것을 알고 싶습니다. 이 wizardthingie를 행동 시키려고 노력하면서 하루 종일 이상을 보냈습니다.
어떤 도움이나 지침이 필요합니다.
감사합니다, 아담 여기
<asp:CreateUserWizard ID="createUserWizard" runat="server"
ContinueDestinationPageUrl="/user/profile/"
CreateUserButtonText="Continue" RequireEmail="False" ActiveStepIndex="0">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server" Title="Account details">
<ContentTemplate>
<fieldset>
<legend>Account details</legend>
<div>
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Desired username:</asp:Label>
<asp:TextBox ID="UserName" runat="server"></asp:TextBox>
</div>
<div>
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Desired password:</asp:Label>
<asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequiredValidator" runat="server" ControlToValidate="Password"
Display="Dynamic" EnableClientScript="false" ValidationGroup="createUserWizard">*</asp:RequiredFieldValidator>
</div>
<div>
<asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPassword">Confirm password:</asp:Label>
<asp:TextBox runat="server" ID="ConfirmPassword" TextMode="Password"></asp:TextBox>
</div>
</fieldset>
<div class="errors">
<asp:ValidationSummary runat="server" ID="validationSummary"
DisplayMode="BulletList" ValidationGroup="createUserWizard"
HeaderText="<b>Please correct the following fields:</b>"
ShowMessageBox="False" ShowSummary="true" />
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="false" />
</div>
</ContentTemplate>
</asp:CreateUserWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
는 코드 숨김의 (이자의 섹션) :
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
createUserWizard.CreatedUser += OnUserCreated;
createUserWizard.CreateUserError += OnError;
createUserWizard.NextButtonClick += OnNextButtonClick;
}
protected void OnUserCreated(object sender, EventArgs e)
{
//Add user to group and redirect to destination page.
}
private void OnNextButtonClick(object sender, WizardNavigationEventArgs e)
{
CreateUserWizard wizard = sender as CreateUserWizard;
if (wizard.ActiveStepIndex == 0)
{
try
{
if (Membership.ValidateUser(createUserWizard.UserName, createUserWizard.Password))
{
MembershipUser newUser = Membership.CreateUser(
createUserWizard.UserName,
createUserWizard.Password);
//add user to group and redirect to destination page
}
}
catch (MembershipCreateUserException ex)
{
SetFailureMessage(ex.StatusCode);
e.Cancel = true;
}
}
}
public void SetFailureMessage(MembershipCreateStatus status)
{
switch (status)
{
case MembershipCreateStatus.DuplicateUserName:
createUserWizard.DuplicateUserNameErrorMessage = "Username is not available."; //the string is fetched from a database.
break;
case MembershipCreateStatus.InvalidPassword:
createUserWizard.InvalidPasswordErrorMessage = "Password is not secure enough"; //the string is fetched from a database.
...
}
}
private void OnError(object sender, CreateUserErrorEventArgs e)
{
if (e.CreateUserError == MembershipCreateStatus.InvalidPassword)
{
CreateUserWizard wizard = sender as CreateUserWizard;
wizard.InvalidPasswordErrorMessage = "Password is not secure enough"; //the string is fetched from a database.
...
}
}
페이지가로드 될 때 오류에 대한 응답으로 오류 메시지 속성을 설정하고 일부 초기화 프로세스의 일부로 설정하지 않는 이유가 있습니까? – pmarflee