ASP.NET Ajax partial postback and jQuery problem

孤街醉人 提交于 2019-12-01 10:31:02

问题


A control contains some HTML and some jQuery to handle a fancy tooltip to display when you click an image within a div.

The control is then used on several different pages, sometimes within an updatePanel, sometimes not.

I have the following code to handle loading the jQuery after a partial postback when the control is displayed within an update panel.

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

   function EndRequestHandler(sender, args) {
      $('img.ormdShipping').each(function(){
            $(this).qtip({

        // some qtip options go here
        })
      });
   }

Problem is, the jQuery doesn't load when the control is used anywhere other than an updatePanel. Do I need a second function that's triggered outside of the EndRequestHandler?


回答1:


Just call it once the page loads as well, you can do that by adding this at the end:

$(EndRequestHandler);

This will cause that code to run both when an UpdatePanel refreshes, and when the page first loads. When you pass in a function to the jQuery constructor, you're calling the jQuery(callback) version, if it's easier to think about, you're doing the short version of this:

$(document).ready(EndRequestHandler); //or..
$(document).ready(function() { EndRequestHandler(); });


来源:https://stackoverflow.com/questions/2691578/asp-net-ajax-partial-postback-and-jquery-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!