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

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

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 ObjectByVal e As System.EventArgsHandles 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. 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.