问题
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);
});
回答1:
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
回答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>
来源:https://stackoverflow.com/questions/9063045/avoid-post-back-while-doing-a-timer-tick-function