Reputation: 29166
I have an ASP page which displays a text box when it loads. It takes an input number, send it to the server through post back, and then displays some record in a grid view. After a number is input into the box, the server fetches some data from a database and add records to the grid view. It also contains a link column, whose URL is set to "#", so that the page isn't redirected when it is clicked.
Now I want to bind a jquery "click" event to that link. How can I do that ? I have tried that to do myself but failed, because it is not available when the DOM is loaded (since it only contains rows when a number is input through the box), and is being modified through ASP.NET Ajax post back.
Upvotes: 1
Views: 1414
Reputation: 887807
You need to call the live
function:
$('#<%=myGrid.ClientID%> a').live("click", function(e) {
//Do things
return false; //You don't need to set the href to #
});
Upvotes: 2
Reputation: 532595
You should be able to use the live handlers in jQuery to do this. I'd give these links a specific class to uniquely identify them and make it easier.
$('a.gridLink').live('click', function() {
... perform your action...
return false; // to cancel the default click action
});
Upvotes: 4