简体   繁体   English

使用jQuery Ajax在Ascx页面中调用webmethod

[英]Call webmethod in ascx page using jquery ajax

For some reasons i want to call webmethod in ascx page from jquery ajax. 由于某些原因,我想从jquery ajax在ascx页面中调用webmethod。

.ascx page .ascx页面

function StartProcessing() {
    ShowProgress();
    $.ajax({
        type: "POST",
        url: "ImportExcel.ascx/btnProcessing_Click",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            alert('hi');

        },
        error: function (data) {
            alert('error');
        }
    });
}

My webmethod in ascx.cs page: 我在ascx.cs页面中的webmethod:

[WebMethod]
    public static void btnProcess_Click(object sender, EventArgs e)
    {
       //code which processes records in excel file
    }

Please suggest some way to call webmethod in ascx from jquery ajax 请提出一些从jQuery Ajax在Ascx中调用Webmethod的方法

Thanks. 谢谢。

Your method must be static like so: 您的方法必须是静态的,如下所示:

[WebMethod]
public static void ProcessExcelRecords()
{
   //code which processes records in excel file
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM