提交按钮不会触发服务器端代码

时间:2009-05-05 21:36:34

标签: asp.net jquery validation submit breakpoints

这个问题说明了一切。我使用jquery的asp.net页面。首先,当我点击提交按钮时,它会显示对象预期的错误。我运行了萤火虫,它显示了'return validate()'函数的错误,该函数被添加到按钮的客户点击上。

  <script type="text/javascript">
    $(document).ready(function() {
        // add custom validation methods
        $.validator.addMethod('phone', function(value, el, params) {
            return this.optional(el) || /^[0-9,+,(), ,]{1,}(,[0-9]+){0,}$/.test(value);
        }, 'Please enter a valid phone number');

        $.validator.addMethod('numbers', function(value, el, params) {
            return this.optional(el) || /^[0-9]+$/.test(value);
        }, 'Invalid entry. Only Numeric is allowed.');


        $.validator.addMethod('domainurl', function(value, el, params) {
            return this.optional(el) || /^(http\:\/\/(?:www\.)?[a-zA-Z0-9]+(?:(?:\-|_)[a-zA-Z0-9]+)*(?:\.[a-zA-Z0-9]+(?:(?:\-|_)[a-zA-Z0-9]+)*)*\.[a-zA-Z]{2,4}(?:\/)?)$/.test(value);
        }, 'Please enter a valid domain url');


        $.validator.addMethod('selectone', function(value, element) {
            return this.optional(element) || (value.indexOf("none") == -1);
        }, 'Please select an option.');



        $("#form1").validate({
            debug: true,
            rules: {
                txt_name: {
                    required: true,
                    minlength: 2
                },
                txt_cmp: {
                    required: true,
                    minlength: 2
                },
                txt_tel1: {
                    phone: true,
                    required: true,
                    minlength: 3

                },
                txt_tel2: {
                    phone: true,
                    required: false,
                    minlength: 3

                },
                txt_mob: {
                    phone: true,
                    required: false,
                    minlength: 9

                },
                txt_email: {
                    required: true,
                    email: true
                },

                txt_domname: {
                    required: true,
                    domainurl: true
                },

                radiobt_domain: "required",

                ddl_yremail: {
                    required: true,
                    selectone: true
                },
                ddl_email: {
                    required: true,
                    selectone: true
                },

                txt_space: {
                    required: true,
                    numbers: true

                },
                txt_calfr: {
                    required: true
                },
                txt_calto: {
                    required: true
                }  


        },
        messages: {
            txt_name: {
                required: "This field is required",
                minLength: "Please enter a valid name"
            },
            txt_cmp: {
                required: "This field is required",
                minLength: "Please enter a valid commpany name"
            },
            txt_tel1: {
                required: "This field is required",
                minLength: "Please enter a valid telephone number"

            },
            txt_tel2: {
                minLength: "Please enter a valid telephone number"
            },
            txt_mob: {
                minLength: "Please enter a valid mobile number"

            },
            txt_email: {
                email: "Please enter a valid email address",
                required: "This field is required"
            },

            txt_domname: {
                required: "This field is required"
            },
            radiobt_domain: "Select the Hosting Type"
        }

    });
});
</script>

我将其删除,现在提交按钮仍无效。服务器端代码没有执行。它没有显示任何错误。我无法弄清楚问题是什么。


我在这里发布了代码:object expected - jquery

2 个答案:

答案 0 :(得分:3)

编辑:看到代码后。即使您在按钮中删除对Validate()的调用后表单仍未提交的原因是因为您有debug:true,这会阻止表单提交。将其更改为debug:false,它将提交。

 $("#form1").validate({
            debug: false,
            .....

答案 1 :(得分:0)

我相信你的问题是表单提交无效,因为你有一个javascript解析错误。您可以检查Firebug控制台,看看页面加载时是否有任何错误。任何javascript错误都可能会破坏表单提交过程。

查看您之前的问题,我猜您可能没有包含验证插件,因为未定义验证。此错误仍可能发生,页面上的其余javascript - 包括所有ASP.NET添加的javascript可能无法解析。

您是否有针对validate插件的脚本包含?它看起来像这样:

 <script type="text/javascript" src="..../jquery.validate.js"></script>