2012-01-30 48 views
2

我需要做更新我的網站上的圖像,而不做回發到頁面。所以,我加載了圖像在ad-rotator中圖像之間的切換。避免做回計時器滴答功能

我還使用計時器滴答功能刷新廣告旋轉器中的圖像。

但是,當計時器滴答函數刷新整個頁面刷新,以便我在頁面中聲明的所有功能重新加載。

我只需要在廣告輪播圖片中的圖片應刷新不是整個頁面。

我需要避免整個頁面的刷新。 請幫幫我。

$(document).ready(function() { 
    setInterval(function() { 
     $('#<% = addrotat.ClientID %>').load(location.href + ' #<% = addrotat.ClientID %> ', '' + Math.random() + ''); 
    }, 5000); 
}); 

回答

2

你需要使用AJAX,通過更新面板與適當的觸發器,更新面板使頁面的部分,而無需回傳被部分呈現。

<asp:UpdatePanel ID="up1" runat="server"> 
     <Triggers> 
      <asp:AsyncPostBackTrigger ControlID="yourControl" EventName="yourControlEvent" /> 
     </Triggers> 
     <ContentTemplate> your content goes here  </ContentTemplate> 

    </asp:UpdatePanel>  

可以通過這個鏈接

update panel, with Triggers

Updatepanel documentation

example for adrotator without refreshing the page

2
//auto refresh clock without postback 

<body> 
    <form id="form1" runat="server"> 
     <asp:ScriptManager ID="ScriptManager1" runat="server"> 
      <script type="text/vbscript" runat ="server" > 
       Private Sub fun() 
        label.Text = Now.ToString 
       End Sub 
      </script> 
     </asp:ScriptManager> 
     <div> 
      <asp:UpdatePanel ID="up1" runat="server"> 
       <ContentTemplate ></ContentTemplate> 
       <Triggers> 
        <asp:AsyncPostBackTrigger ControlID="tim" EventName="Tick" /> 
       </Triggers> 
       <ContentTemplate> 
        <asp:Timer ID="tim" Interval ="1000" Enabled ="true " OnTick ="fun" runat ="server" ></asp:Timer> 
        <asp:Label ID="label" runat ="server" Text="DD/MM/YY"></asp:Label>  
       </ContentTemplate> 
      </asp:UpdatePanel> 
     </div> 
    </form> 
</body> 
+0

我需要刪除 – andrewmcc 2017-07-12 13:34:29

+0

我需要刪除 <康特ntTemplate> 讓它起作用 這是我的C#版本: – andrewmcc 2017-07-12 13:35:50