You must Sign In to post a response.
  • Category: JQuery

    Calling c# method into jquery ajax

    I am calling a c# method using jquery ajax
    My c# method is in .aspx.cs page
    [ScriptMethod(ResponseFormat = ResponseFormat.Xml)]

    public List<ENITYT_SUPPLY.clsDemandDetails> DemandDetails()

    my ajax script in aspx page is


    type: "POST",

    url: "TMSGeoLocator.aspx/DemandDetails",

    dataType: "xml",
    async: true,
    success: function (data) {
    demandMap = $(data);
    error: function (xhr, status, err) {
    var err = eval("(" + xhr.responseText + ")");
    async: false

    The same c# method if i call using webservices(.asmx) its firing the method. if i use in .aspx.cs page its not working can anyone tell me the reason.
  • #762252
    Hello Naresh,

    Refer the below code :

    <script type="text/C#" runat="server">
    public static string GetDate()
    return DateTime.Now.ToString();

    type: 'POST',
    url: 'PageName.aspx/GetDate',
    data: '{ }',
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    success: function(msg) {
    // Do something interesting here.

    You can go through this link for reference :

    Hope this will work for you.

    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

Sign In to post your comments