在更新面板中回发后Jquery无法正常工作 [英] Jquery not working after post back in update panel

查看:74
本文介绍了在更新面板中回发后Jquery无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有asp.net更新面板的jquery,我遇到的问题是在回发后,jquery停止工作并且在控制台中没有显示任何错误,我已经通过以下这个链接。



现在我想要一些优化解决方案因为我在jquery中有很多代码,我已经为文档准备和更新面板重新编写了。

有没有办法在更新面板上使用jquery而不重复代码?



我的尝试:



var prm = Sys.WebForms.PageRequestManager.getInstance( );



prm.add_endRequest(function(){

//在这里重新绑定我的jQuery事件

});

I am using jquery with asp.net update panel, I am facing the problem that after postback,jquery stop working and doesn't show any error in console, I have fixed this issue by following this link.

Now I want some optimize solution as I have alot code in jquery and I have re-write both for document ready and for update panel.
Is there a way to use jquery with update panel without duplicating the code?

What I have tried:

var prm = Sys.WebForms.PageRequestManager.getInstance();

prm.add_endRequest(function() {
// re-bind my jQuery events here
});

推荐答案

使用pageLoad \ pageLoaded并在初始页面加载时以及updatepanel回发后触发,因此您使用它而不是document.ready



如何在updatepanel执行完成后运行javascript ASP.NET论坛 [ ^ ]
Use pageLoad \ pageLoaded and it fires on initial page load and also after an updatepanel postback so you use that instead of document.ready

How to run javascript after updatepanel execution completed | The ASP.NET Forums[^]


尽可能使用委托事件:

直接和委托事件| .on()| jQuery API文档 [ ^ ]

Use delegated events where possible:
Direct and delegated events | .on() | jQuery API Documentation[^]


some-selector-here)。click( function (){
// 仅触发匹配事件时匹配的DOM元素。
/ / 每次UpdatePanel更新时都必须重新附加。
});
("some-selector-here").click(function(){ // Only fires for matching DOM elements that exist when the event is attached. // Must be re-attached each time the UpdatePanel updates. });


这篇关于在更新面板中回发后Jquery无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆