Chosen : jQuery plugin…does not work after postback in asp.net

后端 未结 4 539
遥遥无期
遥遥无期 2021-01-23 10:36

i am using http://harvesthq.github.io/chosen/ control in drop-down list. Everything is going good but i am facing a problem like if i am setting the property of dro

4条回答
  •  轮回少年
    2021-01-23 11:15

    Cause: All jQuery plugins are applied on the Page Load event of the HTML Page or in other words document ready event which is fired when the whole page or document is rendered completely in browser. Now jQuery assigns a unique identification to all controls when applying the plugin. But when some control is inside UpdatePanel and a Partial PostBack occurs the Unique Ids assigned by jQuery is lost and hence the plugin stops working

    Solution: The solution to this problem is that we need to re-apply the jQuery Plugin every time the UpdatePanel’s Asynchronous request or Partial PostBack is completed. For which we can make use of the event handlers provided by the ASP.Net Framework to detect completion of UpdatePanel’s Asynchronous request or Partial PostBack.

    Code

      //On UpdatePanel Refresh
      var prm = Sys.WebForms.PageRequestManager.getInstance();
      if (prm != null) {
          prm.add_endRequest(function (sender, e) {
              if (sender._postBackSettings.panelsToUpdate != null) {
    
                  for (var selector in config) {
                      $(selector).chosen(config[selector]);
                  }
    
              }
          });
      };
    

    add this to your javascript section

提交回复
热议问题