Call .cs Class File(c#) Function From Javascript
Solution 1:
You can not call your C# function directly from your javascript code. As javascript runs on client side and your C# function resides on the server.
For that you have to create a Web Service, and call that service form your javascript using Ajax
.
UPDATE:
- First add the namespace
using System.Web.Services;
to your web page. Add the following method to your page
[WebMethod] public string GetData() { return (""); }
Call the method using
Ajax
.$.ajax({ type: "GET", url: "/GetData", success: function (data) { });
Solution 2:
The only way that you can call a C# function using javascript is if you're running the C# function within an ASP.NET page. Then you would use an ajax call from the javascript to call the ASP.Net page and retrieve the results of your function.
http://api.jquery.com/jQuery.ajax/
function call(){
$.ajax({
url: "/cal_lcs_function_from_js"
}).done(function() {
alert('called');
});
}
where "/cal_lcs_function_from_js" is a page running in ASP.net on the same web server as the javascript file is being run from.
Post a Comment for "Call .cs Class File(c#) Function From Javascript"