日期:2014-05-18  浏览次数:20521 次

使用ajax控件UpdatePanel和Timer控件实现局部刷新,可背景音乐也会从头开始播放
前台:<body>
  <form id="form1" runat="server">
  <div>
  <asp:ScriptManager ID="ScriptManager1" runat="server">
  </asp:ScriptManager>
  <asp:Timer ID="Timer1" runat="server" Interval="10000" ontick="Timer1_Tick1" />
  <asp:UpdatePanel ID="UpdatePanel1" runat="server">
  <contenttemplate>
   
  <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
  </contenttemplate>
  </asp:UpdatePanel>
   
  <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
  <div>
  <%--背景音乐--%>
  <embed name="testMusic" src="sound/wlarm.wav" hidden="true" autostart="true" width="0px" high="0px"
  controls="console" loop="TRUE"></embed>
  </div>
  </div>
  </form>
</body>

我是用Timer控件的ontick事件里实现网页的定时自动刷新,问题是,网页刷新了,可是我第二个div里的背景音乐在每次刷新的时候就会重新开始,注:背景音乐的div是放在UpdatePanel控件外边的

------解决方案--------------------
你把背景音乐放在一个单独的页面中,用iframe引入,这样应该可以了吧。
------解决方案--------------------
探讨
还是我自己解决把,把<asp:Timer ID="Timer1" runat="server" Interval="10000" ontick="Timer1_Tick1" />放到 <contenttemplate> </contenttemplate>标签里边就ok了