I've been hitting my head against this for a little bit now with no progress, so I'd would absolutely love it if someone can shed some light...I have an ASP.Net Forms site, I load a jQuery Dialog to have the user enter an ID, do a required field, and expression validator client-side(which are working fine), then I'm trying to verify that against a SQL table server-side. Problem is I can't get the server-side CustomValidator to fire, I've changed it from an actual validation script to just 'set args.IsValid = false', added 'Page.Validate()' to the top of the submit button function, added a break point to the custom validate Sub and from all appearances the validate action isn't executed and the submit function continues as if the entry was valid.
// Show the Login Dialog
<script>
function showLogin() {
$("#login-dialog").dialog({
height: 380
, width: 500
, modal: true
, buttons: {
'Login': {
text: "Login"
//Login Dialog Login Submit button function
, click: function () {
$("#<%=LoginSubmit.ClientID()%>")[0].click();
return false;
}
}
, 'Register': {
text: "Register"
//Login Dialog Register Button
, click: function () {
$("#<%=RegisterButton.ClientID()%>")[0].click();
return false;
}
}
}
});
};
<%--Login dialog Div--%>
<div id="login-dialog" title="Please Login or Register" hidden="hidden">
<p>If you have already setup an Operator ID you can enter it below, otherwise please register for one.</p>
<asp:RequiredFieldValidator runat="server" ControlToValidate="LoginOperatorID" ErrorMessage="Operator ID is required." CssClass="field-validation-error" />
<asp:RegularExpressionValidator runat="server" ControlToValidate="LoginOperatorID" ErrorMessage="Operator ID must be 4-9 digits" CssClass="field-validation-error" ValidationExpression="[0-9]{4,9}" />
<table id="LoginTable">
<tr>
<td>Operator ID:</td>
<td><input type="password" runat="server" id="LoginOperatorID" maxlength="9" /></td>
<asp:CustomValidator ID="LoginSubmitValidator" runat="server" EnableClientScript="true" Enabled="true"
ErrorMessage="Operator ID does not exist."
ControlToValidate="LoginOperatorID"
OnServerValidate="CheckLoginID" CssClass="field-validation-error" />
</tr>
</table><br />
<input type="button" runat="server" id="LoginSubmit" onserverclick="SubmitLogin" hidden="hidden" causesvalidation="true" />
<input type="button" runat="server" id="RegisterButton" hidden="hidden" onserverclick="RegisterDialog" causesvalidation="false" />
'Validate Operator Login Sub
Protected Sub CheckLoginID(source As Object, args As ServerValidateEventArgs)
args.IsValid = False
End Sub
'Submit Operator Login Sub
Sub SubmitLogin()
Page.Validate()
.....
End Sub
Thanks in advance for any help, it's greatly appreciated!
Update: It definitely seems to relate to the DIV being in a jQuery dialog, per @ShaiCohen's comment, I removed the hidden attribute from both the login button and the div that's used for the dialog causing the dialog div to show in the page as well, when I use the ASP submit button outside the dialog the validation works fine, when I use the ASP button inside the dialog or use the dialog button, the validation doesn't work.
LoginSubmit
button is set to be hidden. That may be your problem. – Shai Cohen