Thursday 24 February 2011

How to display a waiting image on page load in asp net



show loading image on page load
1) First Create the User Control for waiting Image like this


<%@ Control Language="C#" AutoEventWireup="true" Codebehind="ImageLoader.ascx.cs"
    Inherits="ImageLoader" %>
   
<div id="loading"  style="position: absolute; width: 100%; text-align: center; top: 300px; height:100%;">
    <img src="images/Load.gif" border="0" />
</div>


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Project
{
    public partial class ImageLoader : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}

2) Second Register the Control on that page where you display waiting Image and  call JavaScript Function on Body onload="ImageLoader()"   like this:

<%@ Page Language="C#" AutoEventWireup="true" Codebehind="ViewPermissionRequest.aspx.cs"

    Inherits="ViewPermissionRequest" %>
<%@ Register TagPrefix="asp" TagName="loadingImg" Src="~/ImageLoader.ascx" %>
<!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">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>untile page</title>
     <script type="text/javascript" language="javascript">
        function ImageLoader()
            {
                var ld=(document.all);
                var ns4=document.layers;
                var ns6=document.getElementById&&!document.all;
                var ie4=document.all;

                if (ns4)
                      ld=document.loading;
                else if (ns6)
                      ld=document.getElementById("loading").style;
                else if (ie4)
                      ld=document.all.loading.style;

                if(ns4)
                     {
                       ld.visibility="hidden";
                       alert(ns4);
                     }
                else if (ns6||ie4)
                        ld.display="none";
            }
    </script>
</head>
<body onload="ImageLoader()">
<asp:loadingImg ID="imgloader" runat="server" />
    <form id="form1" runat="server">
        <div>
        </div>
    </form>
</body>
</html>




0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Powered by Blogger