Arun
Arun

Reputation: 1704

Avoid post back while doing a timer tick function

i need to do update images in my site without doing post back in a page.So, i loaded the images in ad-rotator to toggl between images.

I also used the timer tick function to refresh the images in the ad-rotator.

But while timer tick function refresh the whole page is refreshed so that all functions that i declared in the page is reloaded.

i need to only images in the ad-rotator images should refresh not the whole page.

i need to avoid whole refresh of the page. Pls help me.

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

Upvotes: 4

Views: 12523

Answers (2)

Suji
Suji

Reputation: 1326

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

Upvotes: 2

Ravi Gadag
Ravi Gadag

Reputation: 15861

You need to use ajax, by using Update panels with proper triggers, update panel Enables sections of a page to be partially rendered without a postback.

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

    </asp:UpdatePanel>    

you can check this links

update panel, with Triggers,

Updatepanel documentation

example for adrotator without refreshing the page

Upvotes: 5

Related Questions