We help IT Professionals succeed at work.

how to refresh a page every 5 mins asp.net c#

Codingitup asked

I've got the below asp.net code. I'm trying to find out how I refresh the page automatically every 5 minutes please.

Many Thanks
<%@ Page Title="" Language="C#" MasterPageFile="~/Global.Master" AutoEventWireup="true" CodeBehind="CurrentRushOrders.aspx.cs" Inherits="Reporting.CurrentRushOrders" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ph_Content" runat="server">
    <h2>Current Rush Orders</h2>
	<asp:GridView ID="GridViewRushOrders" runat="server"  
		Caption="Current Rush Orders on System" AutoGenerateColumns="False" 
			<asp:BoundField DataField="WorkOrder" HeaderText="Work Order" 
				SortExpression="Work Order" ReadOnly="True" />
			<asp:BoundField DataField="SalesOrder" HeaderText="Sales Order" 
				SortExpression="Sales Order" ReadOnly="True" />
			<asp:BoundField DataField="SalesLine" HeaderText="Line No" ReadOnly="True" 
				SortExpression="Line No" />
			<asp:BoundField DataField="Qty" HeaderText="Qty" ReadOnly="True" 
				SortExpression="Qty" />
			<asp:BoundField DataField="CustomerName" HeaderText="Customer Name" 
				SortExpression="Customer Name" ReadOnly="True" />
			<asp:BoundField DataField="RequestedDate" HeaderText="Requested Date" 
				ReadOnly="True" SortExpression="Requested Date" />
			<asp:BoundField DataField="Priority" HeaderText="Priority" 
				SortExpression="Priority" ReadOnly="True" />
			<asp:BoundField DataField="PartNo" HeaderText="Part Number" 
				SortExpression="Part Number" ReadOnly="True" />
			<asp:BoundField DataField="StatusNext" HeaderText="Status Next" 
				SortExpression="Status Next" ReadOnly="True" />
			<asp:BoundField DataField="Carrier" HeaderText="Carrier" 
				SortExpression="Carrier" />
			<asp:CommandField ButtonType="Image" CancelImageUrl="~/Images/cancel_48.png" EditImageUrl="~/Images/edit_48.png"
				ShowEditButton="True" UpdateImageUrl="~/Images/save_48.png" 
                HeaderText="Edit Carrier" />
			<asp:TemplateField ShowHeader="False" HeaderText="Ship It">
                    <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="false" 
                        CommandName="Shipped" ImageUrl="~/Images/autoship_48.png" Text="shipped" CommandArgument='<%#Eval("WorkOrder") %>' />
                        <asp:ConfirmButtonExtender ID="Button1_ConfirmButtonExtender" runat="server" 
                            ConfirmText='<%# AddNumbers(Eval("SalesOrder").ToString(),Eval("SalesLine").ToString())%>' Enabled="True" TargetControlID="ImageButton1">
            <asp:BoundField DataField="Completed" HeaderText="Shipped On" 
                DataFormatString="{0:dd/MM/yy HH:mm} " ReadOnly="True" />
	<br />
	<asp:SqlDataSource ID="SqlDataSourceRushOrders" runat="server" 
		ConnectionString="<%$ ConnectionStrings:jdeConnectionString %>" SelectCommand="sales_RushDisplayOrders" 
        UpdateCommand="	UPDATE dbo.RushOrderStatus SET Carrier = @NewCarrier
		WHERE WorkOrder = @Workorder" 
            <asp:Parameter Direction="Input"  Name="NewCarrier" />
            <asp:Parameter Direction="Input"  Name="Workorder" Type="Int32"  />
	<br />

    <br />
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    <br />
	<br />
	<br />
	<br />

	<br />

Open in new window

Watch Question

Add this to the header... <meta http-equiv="refresh" content="300">

Content number is in seconds.  

Top Expert 2011

If you don't like Rainverse's answer, you could also do it in JavaScript (which, of course, presumes that the user has not disabled javascript):

<script type="text/JavaScript">
function timedRefresh(timeoutPeriod) {
<body onload="JavaScript:timedRefresh(300000);">

Open in new window

The "timeoutPeriod" is defined in milliseconds: 300000 = 300 seconds = 5 minutes


Sorry I'm quite new to asp.net.

I cant find the header. Is this because the page has a masterpage file connected to it?

Best Regards
Top Expert 2011

In my testing, I've found that you can put the meta tag anywhere in the page you want to.  This may not be entirely cross-browser compatible though.  But, if you are working on an internal app where you can explicitly test with the browsers that people are using, you could add it directly to your page.

For example, this page refreshes every 5 seconds
Some text here
<meta http-equiv="refresh" content="5">

Open in new window

You should be able to inject the meta tag with code as follows:

HtmlMeta meta = new HtmlMeta();
meta.Name = "refresh";
meta.Content = "300";

Open in new window