Fire asp.net (link button or button) click event using jQuery

I need to run asp.net (link button or button) click event (server code) using jQuery, the buttons are in the update panel. Please help.

+3
source share
4 answers

What about:

__doPostBack("<%= lnkMyButton.UniqueID %>", "");
+2
source

Michael is good. But I think it's safer to call GetPostBackEventReference . The internal structure of an ASP.NET page may be changed in the future.

Here is a sample code.

  <%= Page.ClientScript.GetPostBackEventReference(lnkButton, "") %>
+4
source

, [WebMethod], , .

, - :

jQuery.ajax({
   type: 'POST',
   contentType: 'application/json; charset=utf-8',
   data: '{}',
   dataType: 'json',
   url: 'MyPage.aspx/SomePageMethod',
   success: function(result){
       alert(result);
   }
});

#, , , VB: http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/

+1

, click LinkButton . - , , _0, _1 .. . , 2 111555 222666. ID, :
contentMain_gridviewMessages_111555_0
contentMain_gridviewMessages_222666_1

, , , , , :

var msgLink = ('a[messageId="' + messageId + '"]');

After that, I used a bit of jQuery to get the automatically generated identifier:

var id = $(msgLink).attr("ID");

When I got the good ole id, javascript did the rest:

document.getElementById(id).click();


Hope this helps someone.

0
source

All Articles