Thursday, 12 September 2013

Customvalidator OnServerValidate event never triggered

Customvalidator OnServerValidate event never triggered

I am trying to create a customvalidator to check if an email is already in
the database at the point of an user registration. I have seen many
similar questions dealing with customvalidators but no answer has brought
any avail.
I have simplified the OnServerValidate method to always return false to
get ANY sort of response but I am not getting any response. I believe that
the method is never being fired. I have come to some conclusion there is
some other issue that is effecting the triggering of the event.
Here is the ASP which is inside a contentplaceholder within the master
page. There is also a scriptmanager in the master file.
<%--email and confirm email--%>
<td>
<ajaxToolkit:TextBoxWatermarkExtender
ID="WatermarkEmail" runat="server"
TargetControlID="Email" WatermarkText="Email"
WatermarkCssClass="watermarked roundedcorner"
/>
<asp:TextBox ID="Email" runat="server"
Columns="48"
CssClass="roundedcorner"></asp:TextBox>
<asp:RequiredFieldValidator ID="EmailRequired"
runat="server" ControlToValidate="Email"
ErrorMessage="E-mail is required."
ToolTip="E-mail is required."
ValidationGroup="UserInformation"
CausesValidation="True"><font
color="red">*</font></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1"
runat="server"
ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ForeColor="Red" ControlToValidate="Email"
ValidationGroup="UserInformation"
ErrorMessage="Invalid Email
Format"></asp:RegularExpressionValidator>
<asp:CustomValidator ID="CheckEmail"
ForeColor="Red" ErrorMessage="This email
already is registered."
ValidateEmptyString="true" display="Dynamic"
ControlToValidate="Email" runat="server"
ValidationGroup="UserInformation"
OnServerValidate="checkEmailValidator_ServerValidate"></asp:CustomValidator>
</td>
</tr>
<tr>
<td>
<ajaxToolkit:TextBoxWatermarkExtender
ID="WatermarkConfirmEmail" runat="server"
TargetControlID="ConfirmEmail"
WatermarkText="Confirm Email"
WatermarkCssClass="watermarked roundedcorner"
/>
<asp:TextBox ID="ConfirmEmail" runat="server"
Columns="48"
CssClass="roundedcorner"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1" runat="server"
ControlToValidate="ConfirmEmail"
ErrorMessage="Confirm E-mail is required."
ToolTip="Confirm E-mail is required."
ValidationGroup="UserInformation"><font
color="red">*</font></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator
ID="regexEmailValid" runat="server"
ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
ForeColor="red"
ControlToValidate="ConfirmEmail"
ValidationGroup="UserInformation"
ErrorMessage="Invalid Email
Format"></asp:RegularExpressionValidator>
</td>
</tr>
And then the server-side script. This has a breakpoint at every line and
NONE of them are ever getting hit. So I am assuming that the method is
never getting triggered.....
protected void checkEmailValidator_ServerValidate(object sender,
ServerValidateEventArgs args)
{
args.IsValid = false;
}

No comments:

Post a Comment