Asp.NET中,postback後會導致,JQuery註冊的事件失效。
參考
- https://msdn.microsoft.com/zh-tw/library/bb383810(v=vs.100).aspx
- 在完成非同步回傳,並將控制項傳回到瀏覽器之後,便會引發 endRequest 事件。 您可以使用這個事件提供通知給使用者或記錄錯誤。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="http://code.jquery.com/jquery-1.10.2.js"></script> | |
<script type="text/javascript" language="javascript"> | |
//postback,jquery事件會失效 | |
//重新註冊按鈕事件 | |
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler); | |
function EndRequestHandler(sender, args) | |
{ | |
initailEvent(); | |
} | |
$(function(){ | |
initailEvent(); | |
}); | |
//重新註冊事件 | |
function initailEvent(){ | |
$('#btnSend').click(function(){ | |
alert('OK'); | |
}); | |
} | |
</script> | |
<input id='btnSend' type='button' value='Send' /> |
沒有留言:
張貼留言