ARTICLE

Auto-refreshing ASP. NET web page using VB.NET

Posted by Rohatash Kumar Articles | ASP.NET using VB.NET June 21, 2011
There are several methods to refresh the asp. net page. Here, we will use Java Script, Meta Tag to refreshing web page automatically.
 
Reader Level:

There are several methods to refresh the asp. net page. Here, we will use Java Script, Meta Tag to refreshing web page automatically.

Using Meta Tag

This is the code to refresh page automatically.
<head>
    <title></title>

    
<meta http-equiv="refresh" content="3">
</head
>

ASP. NET page will automatically refresh after every 2 second.

We can also set url of other page.

<head>
    <title></title>
<meta http-equiv="refresh" content="8;url=http://www.c-sharpcorner.com/">
</head>
 

  • where '8' refers to the number of seconds that will elapse before the page is refreshed;
  • url is the new url redirect to. It can be excluded which means the current page will be reloaded.

Using Java Script

Add the following java script code in the head section of the page.

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication103.WebForm1" %>

<!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></title>

 

     <script type="text/JavaScript">

        function RefreshPage(Period) {

            setTimeout("location.reload(true);", Period);

        }

                 

       </script>

</head>

 

<body onload="javaScript:RefreshPage(5000);">

 

    <form id="form1" runat="server">

    <div>

        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

       </div>

    </form>

</body>

</html>

Now Drag and drop a label control on the form and add the following code on the page load event.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Label1.Text = "TimeOfDay: " & TimeOfDay().ToString()

    End Sub

Now run the application. Page will be refresh after every 5 seconds.

refresh-page1.gif

Figure1.

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor