Home > DeveloperSection > Forums > Call ASP.NET Function From Javascript?
Ashish Pandey

Total Post:128

Posted on    December-27-2013 6:45 AM

 C# C# 

 1 Reply(s)
 1144  View(s)
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?

Alex Leblois
Alex Leblois

Total Post:67

Posted on    December-27-2013 7:09 AM

Hi Ashish,

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


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:


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

Don't want to miss updates? Please click the below button!

Follow MindStick