Solved

Need to display a "Loading" image on Page Load

Posted on 2012-03-26
4
810 Views
Last Modified: 2012-03-30
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
0
Comment
Question by:jazzcatone
  • 2
4 Comments
 
LVL 10

Expert Comment

by:gavsmith
ID: 37766678
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
0
 
LVL 7

Expert Comment

by:Lalit Chandra
ID: 37767060
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.
0
 

Author Comment

by:jazzcatone
ID: 37767249
Actually saw this article and tried this already. Doesn't seem to work with the masterpages.
0
 
LVL 10

Accepted Solution

by:
gavsmith earned 500 total points
ID: 37770272
That won't work with any page, because if you're running a long process in 'page_load' (serverside) it won't render anything at the client until it's finished.

Have you looked into using response.write?

It would look something like:

protected void Page_Load(object sender, EventArgs e)
{
   Response.Write("<html><body><img src='myloadingimage.gif'></body></html>");
   Response.Flush();

   //Create your PDF's here
   .....
   
  //When long process finished you may want to goto a complete page
  Response.Redirect("Complete.aspx");

  //Or show the pdf i.e Response.Redirect("TheNewPDF.pdf");
}

hope that helps
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question