用JavaScript触发UpdatePanel更新的几种方法

1.调用__doPostBack使UpdatePanel刷新。

<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div id="Container" onclick="__doPostBack('UpdatePanel1', '');">
<asp:UpdatePanel runat="server" ID="UpdatePanel1" OnLoad="UpdatePanel1_Load"> <ContentTemplate> <asp:Label runat="server" ID="Label1" /> </ContentTemplate> </asp:UpdatePanel>
</div>

2.触发按钮的click()事件(这样触发click可能在firefox中不起作用,但在ff用jquery来触发似乎就可以)

<asp:Button ID="button" runat="server"
                    OnClick="button_Click" style="display:none;"/>

<asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
  <ContentTemplate>
    <asp:Label ID="label" runat="server"></asp:Label>
  </ContentTemplate>
  <Triggers>
    <asp:AsyncPostBackTrigger ControlID="button" EventName="Click" />
  </Triggers>
</asp:UpdatePanel>

3.来自老赵的杰作,编写一个组件JavaScriptUpdater。

 

前两种方法都是硬编码的意思,老赵的方法可以说更“微软”化。

链接:编写组件,使用JavaScript更新UpdatePanel

 
<script type="text/javascript">
function refreshPanelUpdate()
{
   var obj = document.getElementById("<%= button.ClientID %>");
   obj.click();
}
</script>
posted on 2009-01-17 14:16  honker  阅读(902)  评论(0编辑  收藏  举报