日期:2014-05-17  浏览次数:20494 次

微软ajax框架中,通过异步回发的脚本来激发服务端事件,为何不执行,见内文代码?
如下我仅是想测试,在调用button1按钮后在自动激发button2的事件,但总是不执行,如果在invoke()中加alert();alert会执行。
急救大侠们救助!

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  protected void Button1_Click(object sender, EventArgs e)
  {
  this.Label1.Text = DateTime.Now.ToString() + "updated by button1";
  ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(),"script01",
  "invoke();",true);
  }

  protected void Button2_Click(object sender, EventArgs e)
  {
  this.Label2.Text = DateTime.Now.ToString() + "updated by button2";
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>无标题页</title>
   
   
  <script type="text/javascript">
  function invoke()
  {
  $get('Button2').click();
  }
  </script>
</head>
<body>
  <form id="form1" runat="server">
  <div>
  <asp:ScriptManager ID="ScriptManager1" runat="server">
  </asp:ScriptManager>
  <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
  <ContentTemplate>
  <asp:Label ID="Label1" runat="server" Text="Label1"></asp:Label>
  <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button1" />
  </ContentTemplate>
  </asp:UpdatePanel>
  <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
  <ContentTemplate>
  <asp:Label ID="Label2" runat="server" Text="Label2"></asp:Label>
  <asp:Button ID="Button2" runat="server" Text="Button2" OnClick="Button2_Click" />
  </ContentTemplate>
  </asp:UpdatePanel>
   
  </div>
  </form>
</body>
</html>



------解决方案--------------------
http://msdn.microsoft.com/zh-cn/library/bb399001.aspx
http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032328480&EventCategory=3&culture=zh-CN&CountryCode=CN
http://msdn.microsoft.com/zh-cn/magazine/cc163413.aspx
http://msdn.microsoft.com/zh-cn/library/bb398866.aspx
http://dflying.cnblogs.com/archive/2006/04/01/363998.html
------解决方案--------------------
HTML code

  <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="Button1" />
            
                        </Triggers>

------解决方案--------------------
我在VS 2008里面调试你的程序,一切正常啊!
2009/1/13 上午 09:02:31updated by button1
2009/1/13 上午 09:02:31updated by button2
------解决方案--------------------
我也测试通过
------解决方案--------------------
没发现有什么错误呀?