1

I know I can use ajax to call web method of web-service. can I use ajax to call a simple code behind method?

Thanks!

Elad Benda
  • 35,076
  • 87
  • 265
  • 471

4 Answers4

6

Yes you can. With a little feature called page methods.

Decorate your codebehind method with the [WebMethod] attribute and you can call it from your page via javascript and within your WebForms html.

See this: http://www.singingeels.com/Articles/Using_Page_Methods_in_ASPNET_AJAX.aspx

Also see how to use JQuery to call asp.net page methods.

gideon
  • 19,329
  • 11
  • 72
  • 113
4

You can use the WebMethod attribute

Pagemethods in asp.net

andres descalzo
  • 14,887
  • 13
  • 64
  • 115
2

Yes, you can. See here. It requires putting a ScriptManager tag on your page, and decorating your methods with an attribute.

wsanville
  • 37,158
  • 8
  • 76
  • 101
2

You can do it with or without a script manager. I would suggest looking into the ajax method in jQuery (http://api.jquery.com/jQuery.ajax/) as well as these links:

http://api.jquery.com/jQuery.post/

http://www.infinitelooping.com/blog/2011/05/20/using-jquery-ajax-to-call-web-methods/

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

Gary.S
  • 7,076
  • 1
  • 26
  • 36