我为mouseenter mouseleave设置了绑定的jquery事件,以及jquery draggable。 div被放置在更新面板中,当单击按钮时,信息将被发送到数据库并更新更新面板。但是,当面板更新时,jquery事件不再起作用。知道为什么会这样吗?
答案 0 :(得分:7)
您可以在页面中添加异步触发器,以便在任何异步调用后调用JavaScript / jQuery函数。
将此代码放在您的aspx代码的Page_Load()中:
//This script handles ajax postbacks, by registering the js to run at the end of *AJAX* requests
Page.ClientScript.RegisterStartupScript(typeof(Page), "ajaxTrigger", "Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);", true);
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "EndRequest", "function EndRequestHandler(sender, args){AsyncDone();}", true);
此代码段将专门调用JavaScript / jQuery函数AsyncDone();
答案 1 :(得分:3)
尝试使用
function pageLoad(sender, args)
{
// JQuery code goes here
}
而不是
$(document).ready(function() {
// JQuery code goes here
});
单击更新面板中的按钮时,此功能将起作用;它进入服务器并在它返回时重新添加jquery。但是,这不适用于由eo:AJAXUploader等控件引起的异步回发,但将其与Bryans版本结合使用,您也可以处理异步回发
答案 2 :(得分:3)
从Encosia看一下这个blog post,它会在异步更新后为您提供几种重新绑定的方法。我发现这解决了我的类似问题。
答案 3 :(得分:1)
使用live。
$("div").live("mouseenter", function(){
// do something
});
答案 4 :(得分:0)
/**
* .NET Event Handlers
* When new code is added on to the client by way of
* .NET PostBacks, CSS is typically ignored. This method
* can be used to add CSS to new elements as they are added
* asynchronously. It calls a script at the end of every
* partial post back request.
*
* @example - Core.NETEventHandlers.AsyncPostBack.Init();
*/
var NETEventHandlers: {
/**
* Async Post Back Handler
* calls a script at the end of every partial post back request
*/
AsyncPostBack: {
EndRequest: {
Add: function() {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(NETEventHandlers.AsyncPostBack.EndRequest.Handler);
} // EO Add
, Handler: function(sender, args) {
// Handlers here.
alert('Hello World');
} // EO Handler
} // EO endRequest
, Init: function() {
Sys.Application.add_init(NETEventHandlers.AsyncPostBack.EndRequest.Add);
}
} // EO AsyncPostBack
} // EO dotNETEventHandlers