views:

205

answers:

6

Possible Duplicate:
Call ASP.NET Function From Javascript?

this question is asked by interviewer. can anybody tell me that is it possible? if yes then how.

+6  A: 

You can, but not directly. You'd have to use an AJAX implementation or write an AJAX call yourself using the XmlHttpRequest.

KBoek
+3  A: 

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

Shoban
+1  A: 

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

slugster
+1  A: 

Yes you can. Check Page Methods.

Danny Chen
+3  A: 

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

  1. Using REST style services. I've been using this way ever since I shifted to ASP.Net MVC.
  2. Using Web services (Page Methods, Service Classes). Again Ajax is involved and there are special tools from Microsoft to make this easier.
Cyril Gupta
+10  A: 

Try This

http://stackoverflow.com/questions/2322977/calling-functions-from-an-asp-net-code-file-with-javascript

http://stackoverflow.com/questions/2522967/call-a-c-method-from-javascript

http://globetech.wordpress.com/2008/01/07/call-managed-c-method-from-javascript-code/

http://www.msnewsgroups.net/csharp/t156-how-call-function-javascript.aspx

This all url has diffren examples follow This will suerly help you

Pankaj Mishra
Instead of giving URLs from StackOverflow, it is better to Vote for Close. This way we will have a single point of contact for all such questions.
Aamir