I`m using Javascript function that uses a web service and after finishing it i have to update a Grid Datasource
To accomplish this task i called the javascript function via RegisterClientScriptBlock then call the UpdateGridDataSource method
But While Debugging i found that it calls the UpdateGridDataSource method first .. Then Call the method in the WebService!
ASP.Net Code
System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "delete", "DrawPOI();", true);
UpdateDataSource();
JavaScriptCode
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;
}
WebService :
[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";
}
}
The Problem is that UpdateDataSource() is called before DeletePOI(string ID)