-1

Possible Duplicates:
how to call server side function from client side - asp.net
Calling ASP.NET Code Behind function from Javascript
Calling ASP.NET server side method via JQuery

hi guys, While loading an aspx page, how is it possible to call a server side method with the client side code?Can u show one example?

Community
  • 1
  • 1
user42348
  • 4,181
  • 28
  • 69
  • 98

4 Answers4

0

You'll need ajax for this, one way or another. Either use ASP.NET's built-in 'page methods', or whip up something yourself; your best bet is to use something like jQuery to make the javascript part less painful for you.

tdammers
  • 20,353
  • 1
  • 39
  • 56
0

You can achieve that through and Ajax request. Since you're using asp.net here is a good starting point for some great JavaScript Ajax libraries for it.

Here's also a simple example of how to make a simple Ajax request.

function sampleAjaxReq(){
 var xmlhttp=new XMLHttpRequest();
 xmlhttp.open("POST","resource.asp",true);
 xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
 xmlhttp.send("pname1=value1Henry&pname2=value2");
}
Jose Diaz
  • 5,353
  • 1
  • 31
  • 29
0

If you are working on a non-Ajax project, you can try System.Web.UI.ICallbackEventHandler.

Samples here:

http://msdn.microsoft.com/en-us/library/ms178210%28VS.80%29.aspx

http://www.ajaxmatters.com/2006/05/using-icallbackeventhandler-in-asp-net/

Community
  • 1
  • 1
prashanth
  • 2,059
  • 12
  • 13
0

You can communicate also with Web Services.

SiN
  • 3,704
  • 2
  • 31
  • 36