Link to home
Start Free TrialLog in
Avatar of Codingitup
Codingitup

asked on

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

Hi,

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
Lee
<%@ 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" 
		 onrowdatabound="GridViewRushOrders_RowDataBound" 
		 OnRowCommand="GridViewRushOrders_RowCommand"
         OnRowUpdating="GridViewRushOrders_RowUpdating" 
		DataSourceID="SqlDataSourceRushOrders">
		<Columns>
			<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">
                <ItemTemplate>
                    <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:ConfirmButtonExtender>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Completed" HeaderText="Shipped On" 
                DataFormatString="{0:dd/MM/yy HH:mm} " ReadOnly="True" />
    </Columns>
	</asp:GridView>
	<br />
	<asp:SqlDataSource ID="SqlDataSourceRushOrders" runat="server" 
		ConnectionString="<%$ ConnectionStrings:jdeConnectionString %>" SelectCommand="sales_RushDisplayOrders" 
        UpdateCommand="	UPDATE dbo.RushOrderStatus SET Carrier = @NewCarrier
		WHERE WorkOrder = @Workorder" 
        SelectCommandType="StoredProcedure">
        <UpdateParameters>
            <asp:Parameter Direction="Input"  Name="NewCarrier" />
            <asp:Parameter Direction="Input"  Name="Workorder" Type="Int32"  />
        </UpdateParameters>
    </asp:SqlDataSource>
	<br />

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

	<br />
</asp:Content>

Open in new window

Avatar of Rainverse
Rainverse

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

Content number is in seconds.  

-MJC
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) {
	setTimeout("location.reload(true);",timeoutPeriod);
}
</script>
<body onload="JavaScript:timedRefresh(300000);">
</body>
</html>

Open in new window


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

ASKER

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
Lee
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
<html>
<head>
</head>
<body>
Some text here
</body>
<meta http-equiv="refresh" content="5">
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Rainverse
Rainverse

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial