Solved

Need to display a "Loading" image on Page Load

Posted on 2012-03-26
4
812 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Find out what you should include to make the best professional email signature for your organization.
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…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

756 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