9
Reply

Can we call C# code behind using jQuery?

Nitin Choudhary

Nitin Choudhary

Jan 20, 2015
2.6k
0

    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 Rashid
    January 28, 2015
    3

    YES

    Amaya Pani
    June 17, 2015
    0

    Yes,But it having some prerequisiteC# 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 Salwe
    May 30, 2015
    0

    $.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 Halder
    May 19, 2015
    0

    We can call a Web method using ScriptManager as well. & In javascript, PageMethods.(parameters, onSuccess, onFail);

    Rasmita Dash
    April 03, 2015
    0

    Is it only work with web method?

    Rahul Bansal
    March 31, 2015
    0

    use Jquery.Ajax$.ajax({url: "test.html",context: document.body }).done(function() {$( this ).addClass( "done" ); });

    Abrar Ahmad Ansari
    March 10, 2015
    0

    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 Kumar
    February 27, 2015
    0

    Yes, we can call C# code from jQuery as it supports .net application

    Nitin Choudhary
    January 20, 2015
    0