ASP.NET UpdatePanel 阻止 JQuery 工作

发布于 2024-08-29 11:51:09 字数 527 浏览 2 评论 0原文

我的页面上有一个更新面板,其中一些链接具有触发 JQuery 框弹出的 onClick 事件。除非发生 AJAX 回发,否则这工作正常。我在另一篇文章中看到了一些代码:

Page.ClientScript.RegisterStartupScript(TypeOf(Page), 'ajaxTrigger1', 'Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);', true);
Page.ClientScript.RegisterClientScriptBlock(TypeOf(Page), 'EndRequest1', 'function EndRequestHandler(sender, args){AsyncDone();}', true);

我已经使用过它,但它似乎不起作用。我一直收到 AsyncDone 未定义的信息。有人知道我可以做些什么来解决这个问题吗?

详细信息:ASP.NET 2、IIS7

提前致谢。

I have an update panel on my page with some links that have onClick events that trigger a JQuery box to pop up. This works fine unless an AJAX postback has occurred. I saw some code on another post:

Page.ClientScript.RegisterStartupScript(TypeOf(Page), 'ajaxTrigger1', 'Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);', true);
Page.ClientScript.RegisterClientScriptBlock(TypeOf(Page), 'EndRequest1', 'function EndRequestHandler(sender, args){AsyncDone();}', true);

which I have used but it doesn't seem to be working. I keep getting AsyncDone is not defined. Does anyone have any ideas as to what I can do to sort the issue out please?

Details: ASP.NET 2, IIS7

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

乱了心跳 2024-09-05 11:51:09

问题是,当 updatepanel 触发时,它会替换 dom 中的一大块 html,这意味着它会替换您已将 click 事件绑定到的元素。

要绕过这个问题,请查看 jquery .live().delegate() 不断查找与您提供的选择器匹配的事件,或者如果您想在每次更新面板刷新内容时绑定到内容jQuery updatepanel 插件

The problem is that when the updatepanel fires, it replaces a chunk of html in the dom, which means it replaces the elements that you have bound the click event to.

To bypass this look at jquery .live() or .delegate() which keeps looking for events matching the selector you provide, or if you want to bind to content every time the update panel refreshes content look that the jQuery updatepanel plug-in.

肩上的翅膀 2024-09-05 11:51:09

我通过不使用 jQuery 中的 document.ready 来对此进行排序。相反,我使用:

function pageLoad(sender, args) { //code }

我还没有看到任何不利影响,所以希望这能解决我的问题。

I sorted this by not using the document.ready in jQuery. Instead I used:

function pageLoad(sender, args) { //code }

I haven't seen any adverse effects yet so hopefully this will sort my issue.

笛声青案梦长安 2024-09-05 11:51:09

我使用更新面板只是为了停止 asp.net 中的整个页面刷新,其中甚至包括 jquery。但是在使用更新面板之后,问题得到了解决,但又产生了另一个问题。 jquery 脚本在 updatepanel 内不起作用。

这个问题现在已经解决了。

示例:在 jquery 日期选择器的情况下,Jquery 脚本的通常调用如下所示:

<script type="text/javascript">
    $(function() {
        $("#datepickers").datepicker({
                showOn: "button",
                 buttonImage:   "images/calendar.gif",
                 buttonImageOnly: true
                 });
          });
</script>

即使我使用了与此处出现的解决方案相同的代码

Page.ClientScript.RegisterStartupScript(TypeOf(Page), 'ajaxTrigger1',
'Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);',    true);
Page.ClientScript.RegisterClientScriptBlock(TypeOf(Page), 'EndRequest1', 'function EndRequestHandler(sender, args){AsyncDone();}', true);

http://kopila.com.np/
但它对我不起作用。后来我知道 jquery 脚本在部分回发(即我们的 ajax 请求)后将无法工作。如果我们尝试在更新面板中调用任何 JQuery 脚本,则在第一个 ajax 请求后执行任何脚本将无法工作。

示例:当您使用 asp.net 更新面板时,请再次调用它,如下所示:

<script type="text/javascript">
        function pageLoad(sender, args) {

            if (args.get_isPartialLoad()) {

                $("#datepickers").datepicker({
                    showOn: "button",
                    buttonImage: "images/calendar.gif",
                    buttonImageOnly: true
                }); 

            }

        }
</script>

有关更多详细信息,请访问:http://kopila。 com.np

I used update panel just only to stop the whole page refresh in asp.net which even included the jquery.But after using the update panel somewhat the problem was solved but created another problem. jquery script was not working inside the updatepanel.

This issue is now solved.

Example: In case of jquery Date picker, Usual call of Jquery script appears like this :

<script type="text/javascript">
    $(function() {
        $("#datepickers").datepicker({
                showOn: "button",
                 buttonImage:   "images/calendar.gif",
                 buttonImageOnly: true
                 });
          });
</script>

Even I had used the same code as

Page.ClientScript.RegisterStartupScript(TypeOf(Page), 'ajaxTrigger1',
'Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);',    true);
Page.ClientScript.RegisterClientScriptBlock(TypeOf(Page), 'EndRequest1', 'function EndRequestHandler(sender, args){AsyncDone();}', true);

Solution Appears here: http://kopila.com.np/
But it didnt worked for me.Later I came to know that The jquery script wont work after partial postback i.e.our ajax request.If we try to call any JQuery script inside the update panel do whatever script wont work after the first ajax request.

Example: When you are using asp.net update panel call it again as follows:

<script type="text/javascript">
        function pageLoad(sender, args) {

            if (args.get_isPartialLoad()) {

                $("#datepickers").datepicker({
                    showOn: "button",
                    buttonImage: "images/calendar.gif",
                    buttonImageOnly: true
                }); 

            }

        }
</script>

For More Details Go to: http://kopila.com.np

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文