How can I call a function C# (server side) function in a Javascript function (client side) which triggers the browser is closed? as:
window.onbeforeclose = MyFunction() // C#
How can I call a function C# (server side) function in a Javascript function (client side) which triggers the browser is closed? as:
window.onbeforeclose = MyFunction() // C#
You can not call your server side function from client side , You will need to decorate your C# method with Web Method attribute and make it static to expose it as a callable AJAX member: something like
[WebMethod]
public static void someCSharpFunction() {
// body of function
}
and in your client side
$.ajax({
type: "POST",
url: "SomePage.aspx/someCSharpFunction",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Do something interesting here.
}
});
Hope that helps.
If you are looking to call a server side (c#) method from JavaScript, there are few ways to interact with server side through client side(Javascript):