Wednesday, November 16, 2011

Calling Server Side Code from Client(AJAX)

Mark the ScriptManager as below:-
Source:-
Use PageMethods.Method(Server)
http://forums.asp.net/t/1323698.aspx/1

Assume Page is a.spx

1.(Removed the greater and less than signs...you need to append them) On a.spx
asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
/asp:ScriptManager

2. This is the Client Click Event of Button(on aspx page) from where you would like to Call Server Side Code.
input type="button" id="btnSend" onclick="Send('a','b','c')"

3. Client Method on Aspx Page
function Send(coursme, startme,isme) {

var btn = document.getElementById("btnSend");
btn.disabled = true;

//Server Side Code Call
PageMethods.Send(coursme, startme, isme, Succeeded, Failed);
}

4. You should have a method in a.aspx.cs
[WebMethod]
//public static string Send(string id, int courseRoleId)
public static string Send(string coursme, string startme, string isme)
{
.......................
.......................
Code to Execute on Server
.......................
.......................
}

5. Hopefully you are all set...This is just to give you an idea....

No comments:

Post a Comment