 | Ajax call with WebMethod, get server time |
| using System.Web.Services;
| | 1:
| | 2:namespace Arindam.AjaxWebMethod
| | 3:{
| | 4: public class WebMethodExample
| | 5: {
| | 6:
| | 7: [System.Web.Services.WebMethod]
| | 8: protected static string GetServerTime()
| | 9: {
| | 10: return DateTime.Now.ToLongTimeString();
| | 11: }
| | 12: }
| | 13:}
| | 14: |
|
 | Server side method call from javascript |
| //Set EnablePageMethods=true in ScriptManager
| | 1:
| | 2:<asp:ScriptManager runat="server" ID="scm3" EnablePageMethods="true" >
| | 3: </asp:ScriptManager>
| | 4:
| | 5:<script language="javascript" type="text/javascript" >
| | 6:
| | 7:function getServerTime()
| | 8:{
| | 9: var time= PageMethods.GetServerTime(onSucced,onFailed);
| | 10: alert (time);
| | 11:}
| | 12:
| | 13:function onSucced(result,UserContext,Methodname)
| | 14:{
| | 15:
| | 16:}
| | 17:function onFailed(result,UserContext,Methodname)
| | 18:{
| | 19:
| | 20:}
| | 21:
| | 22:</script>
| | 23: |
|