Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need to display a "Loading" image on Page Load

Posted on 2012-03-26
4
Medium Priority
?
820 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

610 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