---
title: "Call ASP.NET Function From Javascript?"  
description: "Call ASP.NET Function From Javascript?"  
author: "Anonymous User"  
published: 2013-02-13  
updated: 2013-02-13  
canonical: https://www.mindstick.com/forum/598/call-asp-dot-net-function-from-javascript  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Call ASP.NET Function From Javascript?

Hi Everyone!

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.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?

Please reply SASP

Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)

\

## Replies

### Reply by AVADHESH PATEL

Hi Ankita!

There are three way to call asp.net function from JavaScript

i. In your code file (assuming you are using C# and .NET 2.0 or later) add the following Interface to your [Page](https://www.mindstick.com/articles/13031/why-to-make-a-wikipedia-page) Class to make it look like

public partial class Default : System.Web.UI.Page, IPostBackEventHandler{}\
ii. This should add (using Tab-Tab) this function to your code file:

public void RaisePostBackEvent(string eventArgument) { }\
iii. In your onclick event in Javascript write the following code:

var pageId = '<%= Page.ClientID %>';\
__doPostBack(pageId, argumentString);

\
This will call the 'RaisePostBackEvent' method in your code file with the 'eventArgument' as the 'argumentString' you passed from the Javascript. Now, you can call any other event you like.

That is 'underscore-underscore-doPostBack' ... And, there should be no space in that sequence... Somehow the WMD does not allow me to write to underscores followed by a character!


---

Original Source: https://www.mindstick.com/forum/598/call-asp-dot-net-function-from-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
