Thursday, January 15, 2015

Finding PostBack Control from ClientSide JavaScript in ASP .net.

We can Find the Control Creating PostBack in ASP .net webform from ClientSide Script using following Code and Also can Capture the end of Asynchronous postback event in case of update panel  where generally focus is lost after asynchronous post back.

 $(function () {

 Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function (sender, e) {
         if (sender._postBackSettings.sourceElement.id == '<%=ddlLedger.ClientID %>')

                       //Your Control creating postback
                      $("#ctl00_ContentPlaceHolder1_ddlSubLedger_chosen .chosen-single").focus();
         else {
                  //do your thing
                }

            });        
});


Hence on endrequest we can get the postback control on completion of post back and capture the after post back event to do what needed to like may be a focus to next control which is usually lost in case we are using update panel or in case of chosen dropdown.