I want to call CsharpFunction
, a C# function in code-behind, from JavaScript. I tried the code below but whether the JavaScript condition is True
or False
, CsharpFunction
was called regardless!
JavaScript code:
if (Javascriptcondition > 0) { <%CsharpFunction();%> }
C# code behind:
protected void CsharpFunction() { // Notification.show(); }
How do I call a C# function from JavaScript?
Just declare the C++ function extern "C" (in your C++ code) and call it (from your C or C++ code). For example: // C++ code: extern "C" void f(int);
The most basic method for calling C code from R is to use the . C() function described in the System and foreign language interfaces section of the Writing R Extensions manual. Other methods exist including the . Call() and .
You call the function by typing its name and putting a value in parentheses. This value is sent to the function's parameter. e.g. We call the function firstFunction(“string as it's shown.”);
You can use a Web Method and Ajax:
<script type="text/javascript"> //Default.aspx function DeleteKartItems() { $.ajax({ type: "POST", url: 'Default.aspx/DeleteItem', data: "", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { $("#divResult").html("success"); }, error: function (e) { $("#divResult").html("Something Wrong."); } }); } </script> [WebMethod] //Default.aspx.cs public static void DeleteItem() { //Your Logic }
.CS File namespace Csharp { public void CsharpFunction() { //Code; } } JS code: function JSFunction() { <%#ProjectName.Csharp.CsharpFunction()%> ; }
Note :in JS Function when call your CS page function.... first name of project then name of name space of CS page then function name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With