开发者

Attach event to hyperlink click inside update panel?

开发者 https://www.devze.com 2023-01-24 12:33 出处:网络
I am adding a click event (display alert on click) to a html hype开发者_JAVA百科rlink inside an UpdatePanel on document(ready). However, the event never gets fired when I click the hyperlink. Is it be

I am adding a click event (display alert on click) to a html hype开发者_JAVA百科rlink 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;
            });    
    });


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;
         }); 
}
0

精彩评论

暂无评论...
验证码 换一张
取 消