Using jQuery Ajax if your WebMethod is defined as follows:
[WebMethod] public static string GetTime() { return DateTime.Now.ToString(); }
You can call it from your javascript on the page as follows:
$.ajax({ type: "POST", url: "MyPage.aspx/GetTime", contentType: "application/json; charset=utf-8", dataType: "json", success: function(data) { var time = data.d; } });
This is an alternative if you do not want to use ASP.NET auto-generated JavaScript proxies. I personally prefer using jQuery, as it is a universal solution that works with most Web Services .
source share