Tutorial :submit button does not trigger server-side code



Question:

the question says it all. i've an asp.net page using jquery. at first when i clicked the submit button, it'd show the object expected error. i ran the firebug and it displayed the error of 'return validate()' function which was added onClientClick of the button.

  <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>  

i removed it, and now the submit button is still not working. the server-side code is not executing. it isn't showing any error. i can't figure out what is the problem.


i've posted the code here: object expected - jquery


Solution:1

EDIT: After seeing the code. The reason why the form is not submitting even after you remove the call to Validate() in your button is because you have debug:true, this prevents the form submission. Change it to debug: false and it will submit.

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


Solution:2

I believe your problem is that the form submission is not working because you have a javascript parsing error. Can you check the Firebug console to see if there are any errors occuring on when the page loads. Any javascript errors are likely to break the form submission process.

Looking at your previous question, I would guess that you may not have included the validation plugin since validate isn't defined. This error is still probably occurring and the rest of the javascript on the page -- including all the ASP.NET added javascript may not be parsed.

Do you have a script include for the validate plugin? it would look something like this:

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

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »