Pages

Calling code behind function using Ajax

1)Drag scriptmanger in your web page add attribute EnablePageMethods="true" 2)Create functions in javascript section (method name are similar example)       I)CallPageMethod()      II)CallParmeterPageMethod()      III)onSucceeded(result,userContext,MethodName)      IV))OnFailed(error,user) 3)Create static and return string function in Code behind (method name are similar example)     I)MyFirstPageMethod() add attribute [System.Web.Service.WebMethod()]     II)MyFirstParameterPageMehtod() add attribute[System.web.Service.WebMethod()] 4)Call javascript function on input button callPagemethod use event onclick
script code
function  CallPageMethod()
{
debugger;
PageMethods.MyFirstPageMethod(onSucceeded,onFailed);

}
function  CallParametersPageMethod()
{
debugger;
PageMethods.MyFirstParameterPageMethod("This is a Demo",onSucceeded,onFailed);

}

function onSucceeded(result,userContext,methodName)
{
function CallPageMethod()
{;
$get('div1').innerText=result;
}
function onFailed(error,user)
{
debugger;
alert("An error occurred");
}
code behind code [System.Web.Services.WebMethod()] public static string MyFirstPageMethod() { return "Welcome to Ajaax"; }       [System.Web.Services.WebMethod()] public static string MyFirstParameterPageMethod(string sVal) { return "Welcome To ajax world value passed is" + sVal ; }