我做下面的事情来在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)
{
如何实现?
答案 0 :(得分:2)
创建这样的网络方法:
[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) { }
});
});
希望有帮助。