MD Sayem Ahmed
MD Sayem Ahmed

Reputation: 29166

Accessing and binding events to an ASP.NET Grid view using Jquery

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

Answers (3)

SLaks
SLaks

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

tvanfosson
tvanfosson

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

Ju Nogueira
Ju Nogueira

Reputation: 8461

i think you're looking for .live.

Upvotes: 2

Related Questions