我正在尝试使用创建用户向导创建用户。对于电子邮件验证,我使用的是正则表达式控制。我ControlToValidate
为电子邮件文本框的 id 赋予了属性。当我给出错误的电子邮件 ID 并单击创建用户时,它会显示我在其中配置的错误消息,<asp:RegularExpressionValidator>
但它会进入下一步并说用户创建成功。 电子邮件格式错误时如何停止注册用户。我正在尝试CreatingUser
像这样修改事件
protected void CreateUserWizard1_CreatingUser(object sender, LoginCancelEventArgs e)
{
bool allfieldsstatus = false;
RegularExpressionValidator emailvalidator = (RegularExpressionValidator)CreateUserWizardStep1.ContentTemplateContainer.FindControl("emailvalidator");
if (!emailvalidator.Visible)
{
allfieldsstatus = true;
}
if (allfieldsstatus)
{
e.Cancel = false;
}
else
{
e.Cancel = true;
}
}
但这不起作用。可见性属性根本没有显示。我以另一种方式尝试了这种if
情况,因为
if(!emailvalidator.ErrorMessage.length!=0)
{
allfieldstatus = true;
}
这也不起作用。因为该ErrorMessage
属性始终存在于配置中,<asp:RegularExpressionValidator >
对此有什么解决方案?
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server"
CssClass="createUseWizard" AutoGeneratePassword="True" ContinueDestinationPageUrl="~/Account/AdminRegister.aspx"
CreateUserButtonText="Register User"
OnCreatedUser="CreateUserWizard1_CreatedUser" BorderStyle="None"
DisplayCancelButton="True" oncreatinguser="CreateUserWizard1_CreatingUser"
LoginCreatedUser="False">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
<ContentTemplate>
<div id="registerUserDiv">
<div id="registerUserHeader">
Register New User
</div>
<div>
<div class="registerUserLable">
<asp:Label ID="UserNameLabel" runat="server" Text="User Name" AssociatedControlID="UserName"></asp:Label>
</div>
<div class="inputTextbox">
<asp:TextBox ID="UserName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator CssClass="showInRed" ID="UserIDrequired" runat="server" ControlToValidate="UserName"
ErrorMessage="Email is required." ToolTip="User Name is required." ValidationGroup="CreateUserWizard1"
SetFocusOnError="True">*</asp:RequiredFieldValidator>
</div>
</div>
<div>
<div class="registerUserLable">
<asp:Label ID="Label1" runat="server" Text="E-mail" AssociatedControlID="Email"></asp:Label></div>
</div>
<div class="inputTextbox">
<asp:TextBox ID="Email" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator CssClass="showInRed" ID="RequiredFieldValidator1" runat="server"
ControlToValidate="Email" ErrorMessage="E-mail is required." ToolTip="E-mail is required."
ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</div>
<div>
<div class="registerUserLable">
<asp:Label ID="Label2" Text="Select Role" runat="server" />
</div>
<div class="inputTextbox">
<asp:DropDownList ID="rolesDropdown" runat="server">
</asp:DropDownList>
</div>
</div>
<div>
<div class="errorEmail">
<asp:RegularExpressionValidator ID="emailvalidator" runat="server"
ErrorMessage="Email Should be in correct format" ControlToValidate="Email"
SetFocusOnError="True"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
Display="Dynamic"></asp:RegularExpressionValidator>
</div>
</div>
<div>
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
</div>
</div>
</ContentTemplate>
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>