Solved

Need to display a "Loading" image on Page Load

Posted on 2012-03-26
4
803 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now