简体   繁体   English

ASP自定义服务器端验证未触发

[英]ASP Custom Server-Side Validation not firing

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. 我一直对此感到头疼,没有任何进展,因此,如果有人可以提供一些帮助,我绝对会喜欢它的。。。我有一个ASP.Net Forms网站,我将jQuery对话框加载到让用户输入ID,执行必填字段以及表达式验证程序客户端(工作正常),然后尝试在SQL表服务器端进行验证。 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. 问题是我无法启动服务器端CustomValidator,我将其从实际的验证脚本更改为仅“ set args.IsValid = false”,在提交的顶部添加了“ Page.Validate()”按钮功能,在自定义validate Sub上添加了一个断点,并且从所有外观上都没有执行validate操作,并且submit功能继续,就好像该条目是有效的一样。

// 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. 更新:绝对似乎与jQuery对话框中的DIV有关,根据@ShaiCohen的评论,我从登录按钮和用于对话框的div中都删除了hidden属性,导致对话框div也显示在页面中,当我在对话框外使用ASP提交按钮时,验证工作正常;当我在对话框内使用ASP按钮或使用对话框按钮时,验证不起作用。

我最终放弃使用jQuery模态,决定改用CSS来构建Modal,并且在那里进行验证没有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM