0
votes

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
sigh ... show some code, we can't guess what you are doing.Jan Hančič
What you've described should work. We're going to need to code.James Wiseman
I have added the code bit, it works fine when I place the hyperlink outside my update panel but not when its inside the update panel. P.S: Can you set the -1 on my question back to 0 ? I have added the code now ._.Zo Has
we would need some HTML code where this does not work as well, this is much too general to give you an answer... don't worry, this comunity will not steal your code, you can reveal a bit more :)Zathrus Writer
the html would just mean an update panel syntax.And, I never thought anyone of stealing my code.Zo Has

1 Answers

2
votes

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