we can but we need to specify the backend method as static .
Interviews10 answers
Can we call C# code behind using jQuery?
10 Answers
Bidyasagar MishraPosted Jul 12, 2019, 2:19 AM EDT
YES
Amaya PaniPosted Jun 17, 2015, 3:19 AM EDT
Yes,
But it having some prerequisite
C# method mark as webmethod.
Webmethod should be public.
Webmethod also be static.
[webmethod]
Public static YourMethodName( parameter... )
{
}
for your knowledge this method call in two ways one way is Using PageMethods.YourMethodName( Parameter, OnSuccess ,OnFailure ). For this way you required to add on page.
Second way using Jquery Ajax.
Sorry for spelling mistake.
Vaibhav SalwePosted May 30, 2015, 3:29 AM EDT
$.ajax({
type: "POST",
url: "Default.aspx/WebMethodName",
data: '{}',
contentType: "application/json",
dataType: "json",
success: function (data) {
},
error: function (x, e) {
alert("The call to the server side failed. " + x.responseText);
}
})
and your method should be
[webmethod]
public static string WebMethodName()
{
return "success";
}
Shuvojit HalderPosted May 18, 2015, 10:16 PM EDT
We can call a Web method using ScriptManager as well.
& In javascript,
PageMethods.(parameters, onSuccess, onFail);
Rasmita DashPosted Apr 2, 2015, 9:10 PM EDT
Is it only work with web method?
Rahul BansalPosted Mar 31, 2015, 6:55 AM EDT
use Jquery.Ajax
$.ajax({
url: "test.html",
context: document.body
}).done(function() {
$( this ).addClass( "done" );
});
Abrar Ahmad AnsariPosted Mar 10, 2015, 3:06 AM EDT
Yes, we can call C# web method from Jquery for Exmple
JavaScript code
$.ajax({
type: "POST",
url: "CS.aspx/GetName",
data: '{name: abcd }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function(response) {
alert(response.d);
}
});
}
function OnSuccess(response) {
alert(response.d);
}
C#
[System.Web.Services.WebMethod]
public static string GetName(string name)
{
return "Hello " + name ;
}
Navin KumarPosted Feb 27, 2015, 5:54 PM EST
Yes we can call C# Web method from Jquery. Like -
$.ajax({
type: "POST",
url: "Default.aspx/WebMethodName",
data: '{}',
contentType: "application/json",
dataType: "json",
success: function (data) {
},
error: function (x, e) {
alert("The call to the server side failed. " + x.responseText);
}
})
Md. Raskinur RashidPosted Jan 27, 2015, 11:31 PM EST
Yes, we can call C# code from jQuery as it supports .net application
Nitin ChoudharyPosted Jan 20, 2015, 2:52 AM EST







