Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i wanted to call c# code and perform some operation on it .how to call c# code in javascript.
Posted

First you need to understand the fundamental difference between Server Side Code (C#) and Client Side Code (javascript). C# runs on web server (like IIS) and JavaScript runs on browser( like ie,firefox etc). Both of them work in totally disconnected environment where C# can not make call to javascript function directly and same way Javascript can not make direct call to C# code. The only mechanism through which Javascript can make call to C# server side code is through HTTP request. Its up to you how you want to make HTTP call to the server, may be you can you use AJAX call or you can make Normal HTTP post or Get Request.
 
Share this answer
 
Hi,

PageMethods is the answer, below link for similar query:

http://forums.asp.net/t/1938376.aspx?Call+C+function+from+javascript
 
Share this answer
 
v2
A common technique for doing this is to use AJAX to issue a request from the client side and call a web method at the server side. I quite like using jQuery to do this, and here's[^] a handy article demonstrating how to do this.
 
Share this answer
 
may upon the scenario we can try this by using handlers
 
Share this answer
 
Comments
kishorebt 14-Feb-14 7:27am    
can u elaborate it by sample working code
You might look at using singalR,

Its an ASP.NET real time platform using this your javascript can invoice c# code in the server and vice- versa.

Not sure how much this can help you but please do a google
 
Share this answer
 
Comments
kishorebt 14-Feb-14 7:28am    
that what i wanted to do.. from signalr code i wanted to transfer the content to the database so ive to preform the server side script.
Bala Selvanayagam 14-Feb-14 7:55am    
How far you have progressed on this, are you able to populate the data into the SignalR server Hub ? where are you suck please

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900