Attach event to hyperlink click inside update panel?

故事扮演 提交于 2020-01-07 05:04:10

问题


I am adding a click event (display alert on click) to a html hyperlink inside an UpdatePanel on document(ready). However, the event never gets fired when I click the hyperlink. Is it because of ASync postback? What is the correct way to do this?

 $(document).ready(function(){
            $('#addExcl').click(function(){
                alert('asassasaas');return false;
            });    
    });

回答1:


You need to attach the even in every ajax update because the dom struct is change and the events are lost on the part of the update.

var prm = Sys.WebForms.PageRequestManager.getInstance();    
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);

function InitializeRequest(sender, args) {      
}

function EndRequest(sender, args) {
         $('#addExcl').click(function(){
             alert('asassasaas');
             return false;
         }); 
}


来源:https://stackoverflow.com/questions/4162641/attach-event-to-hyperlink-click-inside-update-panel

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