我正在使用使用 Web 服务的 Javascript 函数,完成后我必须更新网格数据源
为了完成这个任务,我通过 RegisterClientScriptBlock 调用了 javascript 函数,然后调用了 UpdateGridDataSource 方法
但是在调试时我发现它首先调用了UpdateGridDataSource方法..然后调用WebService中的方法!
ASP.Net 代码
System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "delete", "DrawPOI();", true);
UpdateDataSource(); 
JavaScript代码
function DeletePOI(arg) {
      //Some Code  
        $.ajax({
            url: "JSBLL.asmx/DeletePOI",
            type: "POST",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            data: "{id:'" + arg + "'}",
            success: function (msg) {
                alert(msg.d);
            },
            error: function (e) {
                alert('Error');
            }
        }); //some code
        return false;
    }
网络服务 :
[WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string DeletePOI(string ID)
        try
            {
                if (id == "")
                    throw new Exception();
                long ID = Convert.ToInt64(id);
                using (GuardEntities database = new GuardEntities())
                {
                    var poi = database.POIs.Where(x => x.ID == ID).FirstOrDefault();
                    database.POIs.DeleteObject(poi);
                    database.SaveChanges();
                }
                return "POI Deleted Successfully";
            }
            catch
            {
                return "Error Occured";
            }
}
问题是 UpdateDataSource() 在 DeletePOI(string ID) 之前被调用