Anand N
What is the best way to call a C# method from Javascript
By Anand N in C# on Jun 10 2013
  • Krishna Mohan
    Apr, 2014 25

    Here i am giving the way by using you can call c# method in javascript In .aspx page create a function something like the show n below function InsertImp(id) { var v1 = 'Id:' + id ; $.ajax( { type: "POST", url: '<%= ResolveUrl("~/Demo.aspx/Demo") %>', data: '{' + v1 + '}', contentType: "application/json; charset=utf-8", dataType: "json", success: function (result) { if (result.status === "OK") { alert('Comment posted'); } else { return false; } }, error: function (req, status, error) { alert("Sorry! Post failed due to error"); } }); } and in your aspx.cs page write in this way (the method which you want to call from javascript function) public partial class Demo : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } [WebMethod] public static int demo(int Id) { return 0; } } In this way you can able to call the C# method from a javascript function. For learning similar kind of questions you can refer this link c# interview questions

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS