Tuesday, 19 February 2013

Refresh Page/Browser Automatically after a Particular Time Period II


Refresh Page/Browser Automatically after a Particular Time Period II


Use the following Code to Refresh Your Page/Browser Every 10 Seconds after Page Load...

Design Part:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Refresh Browser on Button Click</title>
    <meta id="refreshRate" runat="server" http-equiv="refresh" content=""/>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
        <br />
        <br />
        <asp:Button ID="btnRefresh" runat="server" Text="Refresh" OnClick="btnRefresh_Click" />
    </div>
    </form>
</body>
</html>

Code-Behind:


    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text="The Time Now is:"+DateTime.Now.ToShortTimeString();
        refreshRate.Content = "10";
    }

Alternatively, We can start the Page Refreshing Every 10 Seconds after the Button Click .. For that We have to Comment the Event in the Page Load Event and put the Same Code in the Button Click Event:


    protected void Page_Load(object sender, EventArgs e)
    {
        //Label1.Text="The Time Now is:"+DateTime.Now.ToShortTimeString();
        //refreshRate.Content = "10";
    }
    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        refreshRate.Content = "10";
        Label1.Text="The Time Now is:"+DateTime.Now.ToShortTimeString();
    }

No comments:

Post a comment

Thank You for Your Comments. We will get back to you soon.

back to top