2013-10-09 58 views
0

我已经在代码下面的webMethods页ASP.net两个因pagemethods

[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 
} 

后面在aspx页面我有一个元件被同时触发页面方法

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

和Delete(删除) js的功能如下

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

检查控制台在萤火虫显示,这两个Pageme thods被触发 先后

  1. DeleteItems
  2. BindDataTable

但是,有时BindDataTable被删除功能完成承诺其保持在表中从没有刷新在视觉上更新数据库之前开始。

任何想法如何触发调用一个pagemethod只是在前一页pagemethod完成它的服务器端命令后? 感谢

+0

我打过电话的RegisterStartupScript方法从JS调用的绑定PageMethod的C#的DeleteItems功能结束。由于WebMethod是静态的,因此无法在此处使用RegisterStartupScript函数的大部分参数。 –

回答

0

詹姆斯嗨,

  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 

函数删除(){

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

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

谢谢帕特:D :)这很简单! 请接受此礼物 http://rlv.zcache.com.au/gift_idea_for_computer_programmer_butterfly_hat-r09ef249668564a338d5184c64489798b_v9wfy_8byvr_324.jpg –

0

你应该调用这两个方法同步,看到这个帖子:

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

或者你可以称之为第一种方法中的第二种方法,如果你不需要它了别的东西。

+0

感谢Robert,第一个链接是使用c#发布的ASMX文件,这不是我的情况。我的webmethods位于同一页面的代码背后,我使用客户端的PageMethods.FunctionName()调用它们。 并提出第二个建议,请参阅我的问题的第一个评论 –