Skip to content Skip to sidebar Skip to footer

Call Server Side Function From Client Side Javascript

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

Solution 1:

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.

Solution 2:

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

Solution 3:

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/

Solution 4:

You can communicate also with Web Services.

Post a Comment for "Call Server Side Function From Client Side Javascript"