Click here to Skip to main content
15,911,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to show loading image while my page is loading after i click on the link to that page.My page is attached to a master page.
I have displayed the loading image on preinit event of page and hide it at the end of page load,but it doesnt display for normal pages and and for heavy pages for example which displays google maps etc.image gets displayed for a fraction of second and then hides.
C#
protected void Page_PreInit(object sender, EventArgs e)
   {
       try
       {

           ClientScript.RegisterStartupScript(this.GetType(),"Popupshow", "showMessage();", true);

       }
       catch (Exception ex)
       {
           throw ex;
       }
   }
protected void Page_Load(object sender, EventArgs e)
   {
    ClientScript.RegisterStartupScript(this.GetType(),"Popuphide", "hideMessage();", true);
   }


I want the load
ing image to get displayed from the moment i click on the link of that page until it loads completely.

Help Me.

Thanks in advance
Posted
Updated 8-May-15 19:34pm
v3

You have to realise that RegisterStartupScript simply adds js to the html that is going to be sent to the client. That output isn't sent until all the html is ready, ie until all your server code has run. It isn't sent or executed right away. So if your page takes 5 seconds to create;

Browser asks for your page and waits for the output
Page_PreInit adds "showMessage" to the output (browser is still waiting, it has nothing to show)
Page_Onload adds "hideMessage()" to the output (browser is still waiting, it has nothing to show)
Page takes 5 seconds to create, adding all your controls etc to the output (browser is still waiting, it has nothing to show)
Page is finished and output sent to browser in one chunk
Browser gets output then executes showMessage then hideMessage right away.

The only thing you can show a "waiting" message for are resources loaded *after* the html, such as images or any data retrieved via ajax.
 
Share this answer
 
v3
protected void Page_Load(object sender, EventArgs e)
{

image.ImageUrl="Your Image Location";
}

thank you
 
Share this answer
 
Hi,

First of all you need to create one javascript method named "Popupshow"
Secondly create one DIV. Assume that div name is "LoadingDiv"
Third step you need to create another javascript method named "Popuphide"
After doing that please follow below code:

function Popupshow()
{
$("#LoadingDiv").html("Please wait....");
}

function Popuphide()
{
$("#LoadingDiv").html("");
}

Description: When your preinit is called at that time "Popupshow" function call and your loading image or any text starts displaying it. Once your code executing Page Load event and when "Popuphide" method called at that time you have to simply close that div or hide div and give nothing or display none for that.

Hope it will help to you...

Happy Coding...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900