Another alternative is to use AjaxPro.dll. It is a library that was developed by Michael Schwarz that you simply drop in the bin folder of your ASP.NET web applications. You can find more information or download this library at http://www.ajaxpro.info.
To use it:
- Add an
HttpHandler
to your web.config. It should be the first of the HttpHandler
s.
<add verb="*" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
- Register your class for Ajax on the
Page_Load()
event in the .cs file.
public partial class RAAdvice : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(RAAdvice));
- Decorate your method that you want to call from client-side JavaScript with
[Ajaxpro.AjaxMethod()]
.
[Ajaxpro.AjaxMethod()]
public string GetServerTime()
{
return System.DateTime.ToString("HH:mm:ss:fff");
}
- Call your method from your client-side script, i.e., in your .aspx file.
alert(MyPage.GetServerTime().value);
}