Call ASP.NET Function From Javascript?

Total Post:183


 2000  View(s)
Rate this:

Hi Everyone!

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?

Please reply SASP

Thanks in advance



  1. Re: Call ASP.NET Function From Javascript?

    Hi Ankita!

    There are three way to call 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 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!


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.