Call ASP.NET Function From Javascript?

Total Post:128

Points:898
C# 
C#
 1881  View(s)
Ratings:
Rate this:

I'm writing a web page in ASP.NET. I have some Javascript, and I have a submit button with an onClick event.

Is it possible to call a method I created in ASP with Javascript's onClick event?
  1. Post:67

    Points:471
    Re: Call ASP.NET Function From Javascript?

    Hi Ashish,

    I suggest the Microsoft AJAX library. Once installed and referenced, you just add a line in your page load or init:

    Ajax.Utility.RegisterTypeForAjax(GetType(YOURPAGECLASSNAME))

    Then you can do things like:

    <Ajax.AjaxMethod()> _

    Public Function Get5() AS Integer

        Return 5

    End Function

    Then, you can call it on your page as:

    PageClassName.Get5(javascriptCallbackFunction);

    The last parameter of your function call must be the javascript callback function that will be executed when the AJAX request is returned.

Answer