2009-05-05 75 views
1

這個問題說明了一切。我有一個使用jQuery的asp.net頁面。起初當我點擊提交按鈕時,它會顯示對象預期的錯誤。我運行了firebug,它顯示了在按鈕的ClientClick上添加的'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

+1

需要一些代碼示例 – 2009-05-05 21:38:13

+0

這個問題太含糊。我同意鮑比的觀點,儘可能提供儘可能多的代碼。首先要檢查的是「服務器是否獲得了請求?」 – 2009-05-05 21:39:27

回答

3

編輯:看到代碼後。即使您在按鈕中移除對Validate()的調用後,表單仍未提交的原因是因爲您有debug:true,這會阻止提交表單。將其更改爲debug:false,並提交。

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

我相信你的問題是表單提交不工作,因爲你有一個javascript解析錯誤。你可以檢查Firebug控制檯,看看頁面加載時是否有任何錯誤。任何javascript錯誤都可能會破壞表單提交過程。

看看你以前的問題,我猜你可能沒有包含驗證插件,因爲驗證沒有定義。這個錯誤仍然可能發生,並且頁面上的其他javascript(包括所有ASP.NET添加的javascript)可能不會被解析。

你有一個包含驗證插件的腳本嗎?它看起來像這樣:

<script type="text/javascript" src="..../jquery.validate.js"></script> 
相關問題