Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 809
Jeeten Parmar Avatar asked Mar 18 '15 11:03

Jeeten Parmar


2 Answers

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);
});
like image 82
Jeeten Parmar Avatar answered Oct 20 '22 06:10

Jeeten Parmar


Does your DropDown have the AutoPostBack-Attribute?

<asp:DropDownList ID="someIdHere" runat="server" AutoPostBack="true" />
like image 26
Alex H Avatar answered Oct 20 '22 06:10

Alex H