c11ada
c11ada

Reputation: 4334

ASP.net help with auto refresh web page

I am working on a web project where I am required to display data from a interbase database into a grid view. however this data is constantly changing, iv managed to query the database and display the data into a grid view. I am now stuck on how I can automatically refresh the page after 5 minutes so that the new data is queried and displayed.

Can you please advice on how I may achieve the above.

Upvotes: 1

Views: 38435

Answers (7)

Rajib Chy
Rajib Chy

Reputation: 880

In default.aspx page

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <!-- For auto refresh cause use this section-->
    <meta http-equiv="refresh" content="30">
<meta http-equiv="refresh" content="30;url=../account/default.aspx">
<title></title>
</head>

In code behind default.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
   Response.AppendHeader("Refresh", 30 + "; URL=../account/default.aspx");
} 

This web page will automatically refresh every 30s.

Thanks

Upvotes: 0

user1920890
user1920890

Reputation: 21

Use timer control in update panel, set the interval, call a server side event on timer_Tick event, page will refresh at regular interval. Interval is in miliseconds.

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

 <asp:UpdatePanel runat="server" id="TimedPanel" updatemode="Conditional">
    <Triggers>
        <asp:AsyncPostBackTrigger controlid="UpdateTimer" eventname="Tick" />
        <asp:PostBackTrigger ControlID="btnSubmit" />
    </Triggers>
    <ContentTemplate>
     <asp:Timer runat="server" id="UpdateTimer" interval="2000"  OnTick="Timer1_Tick"  /> 

Upvotes: 0

Nuno Agapito
Nuno Agapito

Reputation: 230

You can set the META refresh in a page that derives from the Master Page, you just need to add it on the code in PreRender

HtmlGenericControl ctrl = new HtmlGenericControl("meta");
ctrl.Attributes["http-equiv"] = "refresh";
ctrl.Attributes["content"] = "300";
this.Page.Header.Controls.Add(ctrl);

Upvotes: 2

Jude Cooray
Jude Cooray

Reputation: 19862

Put the GridView inside an UpdatePanel and use a Timer.

Here are some links.

http://ajax.net-tutorials.com/controls/timer-control/ http://mattberseth.com/blog/2007/08/using_the_ajax_timer_control_a.html
http://msdn.microsoft.com/en-us/library/cc295400.aspx

Upvotes: 2

Bibhu
Bibhu

Reputation: 4081

Create the page, with the following META tag in the HEAD section

<META http-equiv = "refresh" URL = "default.html" />

Upvotes: 1

hangar18
hangar18

Reputation: 638

You can write a javascript timer and then refresh the page. Cant recollect the syntax but it should be something like window.location.reload or window.form.reload. You attach the javascript timer function at the end of the Page_Load function.

Upvotes: -1

Oded
Oded

Reputation: 498904

If you are not using AJAX, you can set a META refresh tag to reload the page every 5 minutes.

If you do use AJAX, you can set a setTimeout to refetch the data.

Upvotes: 5

Related Questions