calling an ascx page method using jquery

后端 未结 8 1392
天涯浪人
天涯浪人 2020-12-01 14:16

I know that I can call a page method with jquery using the following syntax

$.ajax({
  type: \"POST\",
  url: \"Default.aspx/GetDate\",
  data: \"{}\",
  con         


        
8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 14:54

    You can write method GetDate() in Default.aspx or an other aspx file AND YOU CAN CALL THAT METHOD FROM .ASCX FILE.

    Ex:

    In UserControl.ascx:

    $.ajax({
     type: "POST",
     url: "Default.aspx/GetDate",
     data: "{}",
     contentType: "application/json; charset=utf-8",
     dataType: "json",
     success: function(msg) {
     // Replace the div's content with the page method's return.
     $("#Result").text(msg.d);
    }
    

    });

    In Default.aspx.cs:

    Public void GetDate() //Public static void { //your code here }

提交回复
热议问题