0
votes

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.

1
It looks like your LoginSubmit button is set to be hidden. That may be your problem.Shai Cohen
Curious, what's with the truly odd placement of the commas?Sparky
@ShaiCohen That was the only workaround I could find to execute the server-side script onclick from within the jQ Dialog because an ASP button doesn't work within it, wasn't aware the hidden button would affect validation, I'll look around for a solution.motoxrdr21
@Sparky I guess I can attribute that to lots of T-SQL work before starting this project, it became habit to put commas at the beginning of the row so if I comment out or delete a row I don't have to mess with the commas above/below, and intellisense adds the extra space after the comma in VS.motoxrdr21
So was the hidden button the problem? And, btw, I do the same thing with commas .... :)Shai Cohen

1 Answers

0
votes

I wound up abandoning using a jQuery modal, and decided to build a Modal using CSS instead, and have had no issues with the validation working there.