Link to home
Start Free TrialLog in
Avatar of Jason Livengood
Jason LivengoodFlag for United States of America

asked on

Need to display a "Loading" image on Page Load

I have a .aspx that uses a master page. On page load it crunches some numbers and creates some pdf's .I need a simple way to display an image called  "loading.gif" that tells the user that the page is processing (creating the pdf's) when it is first displayed. If anybody has a simple way way of doing this when the page first displays it would be much appreciated.

Thanks
Avatar of gavsmith
gavsmith
Flag of United Kingdom of Great Britain and Northern Ireland image

I guess how you do this depends on how nice you would like it to look (or just do the job).

You could just use response.write() and response.flush() on page load to generate a basic load page, before you start the long processing. You would then need something to hide this when complete.

Another way to achieve this, but make it look a little nicer, is display a full page first with a loading image then do a ajax postback to start the long process running, simply remove the loading image on the ajax postback return. Implementation of this is made simple with UpdatePanels, however if performance is of importance you may want to look at creating the call using javascript (or jquery to make it a little bit easier)

hope that helps
For this we will add two div id in the css file. One is the #content id that will contain all the content of body inside it. Its display will be set to ‘none’.

Add another div id #loading that will show the loading gif image. Keep its z-index to a high value like 1000 or so.

div#content {
    display: none;
    }
 
div#loading {
    top: 200 px;
    margin: auto;
    position: absolute;
    z-index: 1000;
    width: 160px;
    height: 24px;
    background: url(loadingimage.gif) no-repeat;
    cursor: wait;
    }

Now add these div id into your html page as follows-

1
2
<div id="loading"></div>
<div id="content">your html content here......</div>
Now add the following javascript code into head section of your html page.

1
2
3
4
5
6
7
<script type="text/javascript">// <![CDATA[
        function preloader(){
            document.getElementById("loading").style.display = "none";
            document.getElementById("content").style.display = "block";
        }//preloader
        window.onload = preloader;
// ]]></script>

Hope this will give the idea to solve your queries.
Avatar of Jason Livengood

ASKER

Actually saw this article and tried this already. Doesn't seem to work with the masterpages.
ASKER CERTIFIED SOLUTION
Avatar of gavsmith
gavsmith
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial