I want to call a function written in .cs code file in a .js (javascript). How to do this? (There a way to call this cs function through Ajax call but dont have much idea about the same.)
-
For example there is a class Sample.cs public class Test { publiv void TestFunction() { // set of code } } the TestFunction is to be called in the javascript function <script type="C#/javascript"> function TestCall() { Test.TestFunction();//////-- //(this is a Cs function, which is to be called, have a look to the Class Test, the defination of the TestFunction is written in that, so this call has to be made) } </script>and this javascript function will be called on some event on the html/ aspx page. For example -- onClick="Testcall();"
-
Answer:
is probably the easiest way to do this, if the JavaScript is running in a browser.
Toby Thain at Quora Visit the source
Other answers
It really depends that which technology stack are you in. I have asp.net background so I will answer with that perspective. If you are working on http://asp.net web forms and you need to call the code behind methods in the Java Script then page methods is the way to achieve this. You can find basic tutorial here http://www.ajaxtutorials.com/quickstart/ajax-tutorial-page-methods-in-asp-net/ You can also use web api or web service to achieve the same. You cs file will be served through wep api request using java scripts calls. Following detailed step by step tutorial will help you to understand the wep api approach. http://www.codeproject.com/Tips/678138/MVC-using-Web-API-and-JQuery-to-GET-or-POST-Data
Muhammad Haseeb Asif
Related Q & A:
- How to call a function with parameter in a bash script?Best solution by tldp.org
- How to call a function asynchronously in PHP?Best solution by Stack Overflow
- If you want to call a USA cell phone (901 555-5555) how would you do it?Best solution by Yahoo! Answers
- I want to find a friend who moved address..... how can i do it.Best solution by Yahoo! Answers
- I want to become a dental nurse but not sure how to?Best solution by nationalcareersservice.direct.gov.uk
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.