Pergunta

I have the following webmethods in the code behind page

[WebMethod]
[ScriptMethod]
public static string BindDataTable()
{
  //This function connects to db gets the result and binds a datatable
}

[WebMethod(EnableSession = true)]
[ScriptMethod]
public static string DeleteItems(int[] ids)
{
 //This function deletes the items
}

In the aspx page i have an element that is triggering both page methods

 <a href="#"  onclick="Delete()"> Delete</a>

and the Delete js function is the following

     function Delete(){
PageMethods.DeleteItems(selectedIds);
PageMethods.BindDataTable();
   }

Inspecting the console in firebug is showing that both Pagemethods are triggered successively

  1. DeleteItems
  2. BindDataTable

However, sometimes the BindDataTable is starting before the delete function is finished committing to database which keeps the table from being visually updated without a refresh.

Any idea how to trigger calling a pagemethod just after a previous pagemethod finishes it's server side commands ? Thanks

Foi útil?

Solução

Hi James ,

          I found one alternate way first call the delete web method once it completed on its success call BindDataTable web method . might be it work

function Delete(){

       PageMethods.DeleteItems(selectedIds);
        function onSucess(result) {
            PageMethods.BindDataTable();
        }

        function onError(result) {
            alert('Something wrong.');
        }
    }
</script>

Outras dicas

You should call those two methods synchronously, see this post:

http://weblogs.asp.net/ricardoperes/archive/2009/03/06/calling-web-service-methods-synchronously-in-asp-net-ajax.aspx

Or you could call the second method inside first method, if you don't need it for something else.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top