views:

101

answers:

4

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?

A: 

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
A: 

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");
}
StudiousJoseph
A: 

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/

A: 

You can communicate also with Web Services.

SiN