Reputation:
Hi guys so i am using javascript to update the page automatically every 5 seconds... But i have noticed the refresh is working but it is not updating my server side data... So the data grid should be updating and it is not... But if i press f5 then the data updates... here is my javascript in the markup.
<script>
//refresh the page (without losing state)
window.setTimeout('document.forms[0].submit()', 5000);
</script>
(In the head)
page load
has all my data i need...
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (DDLProduct.Items.Count == 0)
{
BindDropDownList();
}
BizManager mgr = new BizManager();
mgr.CalcShiftPeriod();
//stores the bizmanager shiftstart to a backing field
_shiftStart = mgr.Shiftstart;
_shiftEnd = mgr.Shiftend;
#if DEBUG
//tests these values if program is in debug version.
_shiftStart = new DateTime(2013, 08, 27, 6, 00, 00);
//dismisses if in release version
_shiftEnd = new DateTime(2013, 08, 27, 13, 59, 59);
#endif
//passing in the params to the refreshdata method.
RefreshData(Product, _shiftStart, _shiftEnd);
}
}
So in essence the page is refreshing but the data is not unless i do a f5 refresh.
Upvotes: 0
Views: 1783
Reputation: 5030
I don't know why you are Reloading your page in every 5 sec
answer by Esko will work for you but
You can also refresh through use of Meta Refresh
like this
<head>
<meta http-equiv="refresh" content="10">
</head>
I suggest you to do that like this:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel runat="server" UpdateMode="Conditional">
<ContentTemplate>
<!-- your GridView in UpdatePanel -->
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
<asp:Timer ID="Timer1" runat="server" Interval="2000" OnTick="Timer1_Tick"></asp:Timer>
Backend Code:
protected void Timer1_Tick(object sender, EventArgs e)
{
// your code to refresh after some interval
}
Upvotes: 1
Reputation: 4207
You are not actually refreshin the page, but submitting the form, hence creating a postback. In your Page_Load, you don't refresh the data if it's postback.
Try changing the javascript to:
<script>
window.setTimeout(function() {
location.reload();
}, 5000);
</script>
Upvotes: 5