在页面加载时显示加载图像 [英] show loading image when the page is loading

查看:74
本文介绍了在页面加载时显示加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在点击指向该页面的链接后加载我的页面时显示加载图像。我的页面附加到母版页。

我在preinit事件中显示了加载图像在页面加载结束时隐藏它,但它不显示正常页面和重页面,例如显示谷歌地图等。图像显示几分之一秒然后隐藏。

 受保护  void  Page_PreInit( object  sender,EventArgs e)
{
try
{

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

}
catch (例外情况)
{
抛出 ex;
}
}
受保护 void Page_Load( object sender,EventArgs e)
{
ClientScript.RegisterStartupScript( this .GetType(),< span class =code-string>
Popuphide hideMessage(); true );
}





我希望从我点击的那一刻开始显示负载

ing图像在该页面的链接上,直到它完全加载。



帮助我。



提前致谢

解决方案

你必须意识到RegisterStartupScript只是将js添加到将要发送到客户端的html中。在所有html准备就绪之前,即在所有服务器代码都运行之前,不会发送该输出。它不会立即发送或执行。因此,如果您的页面需要5秒钟来创建;



浏览器请求您的页面并等待输出

Page_PreInit将showMessage添加到输出(浏览器仍在等待,它没有任何显示)

Page_Onload将hideMessage()添加到输出(浏览器仍在等待,它没有任何显示)

页面需要5秒钟才能创建,将所有控件等添加到输出中(浏览器仍在等待,它没有任何显示)

页面已完成并且输出已发送到浏览器中一个块

浏览器获取输出,然后立即执行showMessage,然后执行hideMessage。



唯一可以显示等待消息的是资源加载*之后* html,例如图像或通过ajax检索的任何数据。


protected void Page_Load(object sender,EventArgs e)

{



image.ImageUrl =你的形象位置;

}



谢谢





首先你需要创建一个名为Popupshow的javascript方法

其次创建一个DIV。假设div名称是LoadingDiv

第三步你需要创建另一个名为Popuphide的javascript方法

完成后请按照以下代码:



函数Popupshow()

{


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.

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

解决方案

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.


protected void Page_Load(object sender, EventArgs e)
{

image.ImageUrl="Your Image Location";
}

thank you


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()
{


这篇关于在页面加载时显示加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆