Auto Redirection within Some Time in ASP.Net


Introduction and Demonstration

In many websites we use to see loding……loding like images or texts are being flashed. Actually that is nothing more than some line of codes. Assume that we have two pages in our web application project named Default.aspx and Home.aspx. Also assume that corporate home page will be Home.aspx and Default.aspx page will be used for flash the images or texts. Now we will map our Domain Name Server (DNS) to Default.aspx page. But in our Default.aspx page has nothing more than a flash image as given in screenshot below.

auto.gif

It is Default.aspx page above, which has a .gif image only. But this page has feature to redirect on Home.aspx page after some defined time. So, let's take a look at code.

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!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>Auto Redirection within Some time in ASP.Net</title>

<script type="text/javascript">
function delayer()
{
window.location = "Home.aspx"
}
</script>

</
head>
<
body onLoad="setTimeout('delayer()', 5000)">
    <form id="form1" runat="server">
    <div>
        <table width="100%" align="center">
            <tr>
                <td colspan="3">
                    <img src="loding/loding.gif" /></td>
            </tr>
        </table>

      </div>
    </form>
</body>
</
html>

In above coding, there are two major thing to underline are

<script type="text/javascript">
function delayer()
{
window.location = "Home.aspx"
}
</script>

Above code is just a JavaScript function which has only a location. But now we have to call this JavaScript function from body after some time as in body.

<body onLoad="setTimeout('delayer()', 5000)">

This coding will redirect us on Home.aspx page after 5 seconds.


HAVE A HAPPY CODING!
 

Up Next
    Ebook Download
    View all
    Learn
    View all