簡體   English   中英

在執行計時器滴答功能時避免回發

[英]Avoid post back while doing a timer tick function

我需要在我的網站上更新圖像而不在頁面中回發。所以,我在ad-rotator中加載圖像以在圖像之間切換。

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

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

我需要只在廣告 - 旋轉器圖像中的圖像應該刷新整個頁面。

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

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

您需要使用ajax,通過使用具有適當觸發器的Update面板,更新面板使頁面的各部分能夠在沒有回發的情況下進行部分呈現。

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

    </asp:UpdatePanel>    

你可以查看這個鏈接

更新面板,帶觸發器

Updatepanel文檔

沒有刷新頁面的adrotator示例

//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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM