asp.net 如何在按钮点击时调用EQUAC?

w46czmvw  于 2023-10-21  发布在  .NET
关注(0)|答案(1)|浏览(158)

我正在做下面这样的调用clikc上的asyn

private List<SuggestedItemsInput> suggestedItemAsync()
    {
        OHDWebService OHDService = new OHDWebService();
        List<SuggestedItemsInput> suggestedItemsList = OHDService.SaveSuggestedItems(ViewState["Body"].ToString(), hfdOrderRecordID.Value);
        return suggestedItemsList;
    }

onclick

protected async void imgbtnClaim_Click(object sender, EventArgs e)
    {
        try
        {
            Task<List<SuggestedItemsInput>> task = new Task<List<SuggestedItemsInput>>(suggestedItemAsync);
            task.Start();
            lblError.Text = "Please Wait. Proccessing...";
            List<SuggestedItemsInput> suggestedItems = await task;
            if (suggestedItems.Count > 0)
            {

但它是阻塞的UI,thousing错误如下

如何才能做到这一点?

alen0pnh

alen0pnh1#

创建一个像这样的webmethod:

[WebMethod]
public async Task Yourmethod(string value)
{
value = "abc";
  return value;
}

然后从你的前端使用jquery来点击这个方法,像这样:

<script>
$(fucntion(){
    $.ajax({
        type: "POST",
        url: "..../Yourmethod",
        data: '{}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: true,
        success: function (data) { }
    });
});

希望有帮助。

相关问题