Call Code behind method from javascript

rajeeva_nagaraj
rajeeva_nagaraj used Ask the Experts™
on
Hi,

I have written a java script function which shows an alert message after some calculation, now i want to execute a code behind method (C# method) after that alert is shown.
Please its very urgent.

Regards
Rajeeva
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Hey you can achieve this using page methods.

here we go

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

You can call the server side functions from client side using javascript.

if you anything let me know.
Use this

function CallBackRequest(url,params,Callback)
{
    var xmlHttp;
    try
    {  
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
      // Internet Explorer
      try
      {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e)
      {
        try
        {
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e)
        {
          alert("Your browser does not support AJAX!");
          return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
    {
      if(xmlHttp.readyState==4)
        Callback(xmlHttp.responseText);
    }
    if(params== null)
    {
      xmlHttp.open("GET",url,true);
      xmlHttp.send(null);
    }
    else
    {
      xmlHttp.open("POST",url,true);
      xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xmlHttp.setRequestHeader("Content-length", params.length);
      xmlHttp.setRequestHeader("Connection", "close");
      xmlHttp.send(params);
    }
}

Commented:
you may use _doPostBack method to execute server side event..like

__doPostBack('ButtonID','')
// if you are using master page than use <%= ButtonID.ClientID %>

for more info

http://wiki.asp.net/page.aspx/1082/dopostback-function/
Amit TripathiSharePoint Architect

Commented:
You can use XML http for it ,it's goes in to server and do what ever you want....

Author

Commented:
Hi All

I found solution, code behind method can be called from java script but using web methods

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial