Possible Duplicate:
Call ASP.NET function from JavaScript?
"Can you call a C# function from JavaScript?" was asked by an interviewer. Is it possible? If yes, then how?
Possible Duplicate:
Call ASP.NET function from JavaScript?
"Can you call a C# function from JavaScript?" was asked by an interviewer. Is it possible? If yes, then how?
You can, but not directly. You'd have to use an AJAX implementation or write an AJAX call yourself using the XmlHttpRequest.
You cannot call server-side code ‘directly’ from client-side code. That is because by design, the server side code executes at server side and client side code at the client. However there are some workarounds. To call serverside code from javascript, you will need to use AJAX, and the easiest way out, is to use the ASP.NET AJAX Extensions.
Check this link
How to call Server Side function from Client Side Code using PageMethods in ASP.NET AJAX
You can call C# functions through JavaScript, but not directly. That is to say, you just can't include the namespace and make a direct call to the function. The request has to go indirectly through an interface at the web server which handles browser requests and then sends them to the functions. There are several ways of doing this
Or you can call a managed C# (or whatever) language function in a Silverlight control by calling through the JavaScript bridge.
This is one of those tricky questions where the answer is "not directly, but with a little help from Ajax or the web page DOM I can, and this is how I do it...".