---
title: "Call ASP.NET Function From Javascript?"  
description: "Call ASP.NET Function From Javascript?"  
author: "Anonymous User"  
published: 2013-12-27  
updated: 2013-12-27  
canonical: https://www.mindstick.com/forum/1844/call-asp-dot-net-function-from-javascript  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Call ASP.NET Function From Javascript?

I'm [writing](https://www.mindstick.com/articles/12997/5-essential-tips-on-resume-writing-for-business-analysts) a [web page](https://www.mindstick.com/forum/718/sql-server-report-alignment-to-center-of-web-page) in [ASP](https://www.mindstick.com/articles/751/introduction-to-asp-dot-net-mvc).NET. I have some [Javascript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript), and I have a [submit button](https://www.mindstick.com/forum/12834/make-text-appear-when-submit-button-clicked-and-checkbox-is-unchecked) with an [onClick](https://www.mindstick.com/forum/12718/onclick-for-hyperlink) [event](https://www.mindstick.com/articles/167719/marquee-hire-benefits-of-event-lighting-hire-london).

Is it possible to call a [method](https://www.mindstick.com/forum/166/webservice-method) I created in ASP with Javascript's onClick event?

## Replies

### Reply by Anonymous User

Hi Ashish,

I suggest the Microsoft AJAX library. Once installed and referenced, you just add a line in your [page](https://www.mindstick.com/articles/13031/why-to-make-a-wikipedia-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.


---

Original Source: https://www.mindstick.com/forum/1844/call-asp-dot-net-function-from-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
