Calling a C# method using jQuery on the client side
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...
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 theHttpHandler
s. - Register your class for Ajax on the
Page_Load()
event in the .cs file. - Decorate your method that you want to call from client-side JavaScript with
[Ajaxpro.AjaxMethod()]
. - Call your method from your client-side script, i.e., in your .aspx file.
<add verb="*" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
public partial class RAAdvice : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(RAAdvice));
[Ajaxpro.AjaxMethod()]
public string GetServerTime()
{
return System.DateTime.ToString("HH:mm:ss:fff");
}
// Remember to prefix your method with the class name of your page.
alert(MyPage.GetServerTime().value);
}