View Full Version : Help - ASP.NET function to Javascript

10-09-2012, 03:38 AM
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?


Old Pedant
10-09-2012, 10:13 PM
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.