Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2012
    Thanked 0 Times in 0 Posts

    Help - ASP.NET function to Javascript

    Hi experts, just want to ask if it is possible to call the function of ASP.NET to Javascript button just like this example function.

    Function SaveDocument As Boolean 
    Response.Write("You call me")
    End Function
    How to call this SaveDocument function in JavaScript?

    Last edited by gimomars; 10-09-2012 at 04:08 AM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Thanked 4,731 Times in 4,693 Posts
    You can't.

    JavaScript is running in the user's browser, maybe in a plane flying across Germany.

    ASP.NET is running on the server, maybe in a computer room in Sydney, Australia.

    How can you expect the browser to magically be able to reach across the ocean and get ASP.NET to do something?

    The *ONLY* way to cause ASP.NET code (or ANY server-side code) to do anything is to make an HTTP request. Especially in the case of ASP.NET code, that pretty much means that you must post the <form> *back* to the server.

    Now, you *could* use JavaScipt to invoke the "click" of some ASP.NET-generated button, but to do that you would have to first look at what ASP.NET actually is generating for that button.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts