Search code examples
c#jqueryupdatepanel

jQuery Validation with Update Panel C#


I am using UpdatePanel for asp.net Controls. So, to validate it I am using jquery onEachRequest. It is also working fine.

But, main issue is that It stops executing postback of DropDownList. Means, It does not postback to retrive data.

My Code :

function onEachRequest(sender, args) {
    if ($("#form1").valid()==false) {
          args.set_cancel(true);
    }
}
function pageLoad() {           
      $('#<%= btnPayment.ClientID %>').click(function () {
            $("#form1").validate({
                rules: {
                    <%=txtName.UniqueID %>: {
                        required: true
                    }
                }, messages: {
                    <%=txtName.UniqueID %>:{
                        required: "Please enter Name."
                }
                }
            });

        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_initializeRequest(onEachRequest);
      });
}

How to solve this issue ?


Solution

  • I used below code to solve my problem :

    function onEachRequest1(sender, args) {
         args.set_cancel(false);
    }
    
    $('#<%= Dropdown Id.ClientID %>').change(function () {
         var prm = Sys.WebForms.PageRequestManager.getInstance();
         prm.add_initializeRequest(onEachRequest1);
    });