What are other suggestions and sample code for efficiently validating the Register and/or login page. Perhaps use of jQuery?
I would like to use some ajax to inform the user the email address is in use for example.
Register.aspx
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="CreateUserWizard1" />
<asp:CustomValidator id="CustomValidator1" runat="server" ValidationGroup="CreateUserWizard1"
Display="None" EnableClientScript="False"></asp:CustomValidator>
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" oncreatinguser="Createuserwizard1_CreatingUser">
<WizardSteps>
<asp:CreateUserWizardStep runat="server" >
<ContentTemplate>
<table border="0">
<tr>
<td align="center" colspan="2">
Sign Up for Your New Account</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
</td>
<td>
<asp:TextBox ID="UserName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
ControlToValidate="UserName" ErrorMessage="User Name is required."
ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
</td>
<td>
<asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
ControlToValidate="Password" ErrorMessage="Password is required."
ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="ConfirmPasswordLabel" runat="server"
AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label>
</td>
<td>
<asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server"
ControlToValidate="ConfirmPassword"
ErrorMessage="Confirm Password is required."
ToolTip="Confirm Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label>
</td>
<td>
<asp:TextBox ID="Email" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="EmailRequired" runat="server"
ControlToValidate="Email" ErrorMessage="E-mail is required."
ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:CompareValidator ID="PasswordCompare" runat="server"
ControlToCompare="Password" ControlToValidate="ConfirmPassword"
Display="Dynamic"
ErrorMessage="The Password and Confirmation Password must match."
ValidationGroup="CreateUserWizard1"></asp:CompareValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
</table>
</ContentTemplate>
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep runat="server" />
</WizardSteps>
</asp:CreateUserWizard>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
Register.aspx.cs
protected void Createuserwizard1_CreatingUser(object sender, LoginCancelEventArgs e)
{
CreateUserWizard1.UserName.ToLower();
// Check if the user name exists or email is in use.
CreateUserWizard cuw = (CreateUserWizard)sender;
cuw.Email = cuw.UserName;
TextBox passwordTextBox =
(TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Password");
TextBox confirmPasswordTextBox =
(TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ConfirmPassword");
CustomValidator1.IsValid = false;
CustomValidator1.ErrorMessage = "I think the email is in use.";
// Save password in the textbox
passwordTextBox.Attributes.Add("Value", cuw.Password);
passwordTextBox.Attributes.Add("Value", cuw.ConfirmPassword);
e.Cancel = true;
}
protected void Button1_Click(object sender, EventArgs e)
{
CustomValidator1.IsValid = false;
CustomValidator1.ErrorMessage = "Hello errors";
}