I'm having a problem with validating an email address for proper form (not if it is an actual live email address). In the case of a mis-typed email address, the following code works fine and I suppose I can live with this. However, it is a work-around to avoid a problem. The work-around is the use of the "alert" in the jquery script. As long as I include this alert the code works OK. If I remove the alert then the code does not work correctly after the user reenters a properly formed email address - the user has to click the "create user" button twice for actual create user process to fire. The first click takes focus off on the email text box and allows the validation process to run. If the validation process determines that the email is now correctly formatted, the process just sits there and the user has no clue what is happening. If they decide to click the button again, then the create user process is fired and all is well. However, this is no way to run the show! The reason the alert works is not clear to me - has something to do with moving the focus. Also, the "focus" code in the jquery does not seem to work.
I've tried all kinds of variations for this problem and posted on the Microsoft ASP forum and so far no one has a clue how to fix this. It seems that I should just be able to put the regular expression in the properties option for email validation and that should be it. However, that produces the same problem. Trying to trap the create user button is difficult because of the internal timing of the CreateUserWizard - I tried lots of variations of this approach.
The following code is pretty simple but it seems that I'm not understanding some fundamental thing about how to validate an email and still have the normal flow. The normal flow should be:
1. User enters bad email format, clicks Create User and then gets an error message in the usual place
2. User enters a good email, clicks Create User and the create user process proceeds normally
BTW, this does not seem to be a problem if I leave in the security questions. But, I don't want the security question.
<%@ Page Title="" Language="
VB" MasterPageFile="~/MasterPages/1Column.master" AutoEventWireup="false" CodeFile="SignUpTest.aspx.
vb" Inherits="SignUpTest" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script type="text/jscript" src="../scripts/jquery-1.7.2.min.
js">
</script>
<script type="text/jscript">
$(function ()
{
$("#ContentPlaceHolder1_CreateUserWizard1_CreateUs erStepContainer_Email").bind('change', function (event)
{
if (/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test($(this).val()))
{
$("#ContentPlaceHolder1_CreateUserWizard1___Custom Nav0_StepNextButton").trigger('click')
}
else
{
alert("Please use a valid email")
$("#ContentPlaceHolder1_EmailErrMsg").text("Plea se enter a valid email address")
$("#ContentPlaceHolder1_CreateUserWizard1_CreateUs erStepContainer_Email").trigger('focus')
};
});
});
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" >
<ErrorMessageStyle BackColor="#FFFFCC" BorderColor="Black"
BorderStyle="Solid" />
<ValidatorTextStyle BackColor="#FFFFCC" />
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
<CustomNavigationTemplate>
<table border="0" cellspacing="5" style="width:100%;height:100%;">
<tr align="right">
<td align="right" colspan="0">
<asp:Button ID="StepNextButton" runat="server" CommandName="MoveNext"
Text="Create User" ValidationGroup="CreateUserWizard1"/>
</td>
</tr>
</table>
</CustomNavigationTemplate>
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
<asp:Label ID="EmailErrMsg" runat="server" Text=" " ForeColor="Red"></asp:Label>
</asp:Content>
There is no code-behind. Thanks for any insight on this problem.