在 asp.net 页面加载时显示 gif
我有一个很长的 ASP.NET 页面加载过程。
有没有办法在 ASP.NET 页面加载时显示加载 gif?
显然我不能在页面本身上使用图像,当我第一次加载带有“正在加载...”图片的“虚拟页面”时,一旦我将用户重定向到真实页面,该页面就会被丢弃。 有什么
线索吗?谢谢
I have a lenghty ASP.NET page load process.
Is there a way to display a loading gif while the ASP.NET page loads?
Obviously I can't use an image on the page itself, and when I fiirst load a "dummy page" with the "Loading..." picture, that page is discarded as soon as I redirect the user to the real page...
Any clue? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以为此使用 UpdateProgress 控件,如下所示:
如果您希望它是半透明的,您可以使用以下一些样式:
You can use an UpdateProgress control for this, like this:
Here are some styles you can use if you want it to be semi-transparent:
请参阅我的类似问题使用 jQuery 或 AJAX 的“请稍候”消息?:
加载 ASPX 页面时,您将停留在 Web 浏览器中的当前页面。因此,当您知道新页面正在加载时(即,按下按钮或链接时),只需显示“正在加载”图像,当客户端完成接收“新”页面(无论它是实际的)时,它就会自动消失新页面或回传的同一页面)。
单击提交按钮时,您可以使用自动显示加载图像(包含在
div
中)的示例代码如下:或者,您可以使用附带的
UpdatePanel
在 Ajax 工具包或 ASP.NET 4.0 中。它有一个名为UpdateProgress
的控件,可以自动显示加载图像。编辑:
我认为您的意思是您希望在加载第一个页面之前显示“正在加载”图像,在这种情况下,您应该将母版页内容包裹在
UpdatePanel
,使用自动显示图像的进度加载器控件(在 Ajax 工具包或 ASP.NET 4.0 中都可用),并在初始设置之后加载页面的实质性(非母版页)内容。页面加载在更新面板
。为此,您可以将内容页面的正文放入
Panel
中,将面板的可见性设置为False
,然后将其设置为True
页面加载后。UpdateProgress
控件的标记如下。当然,您希望对其进行样式设置并将其放置在正确的区域。编辑:
如果您不想使用
UpdatePanel
和UpdateProgress
控件,则只需执行以下操作:pnlContent
并将面板的可见性设置为False
。img
和您的加载图像,并将其放入名为pnlLoading
的单独Panel
中,并将可见性设置为True
。放置一个客户端脚本,强制页面在加载后立即重新加载。将此脚本放入
pnlLoading
中。 更新:将下面的 #3 代码放入您的 ASPX 页面中以创建面板,它将立即触发回发。将以下 #4 代码添加到您的
Page_Load
中。代码:
对于 #3:
对于 #4:
这将导致在加载实际页面内容时显示加载图像。
Please see my similiar question "Please Wait" message using jQuery or AJAX?:
While the ASPX page loads, you will stay on the current page in the web browser. So when you know the new page is loading (i.e., when a button or link is pressed), simply show the "Loading" image and it will automatically disappear when the client is finished receiving the "new" page (whether it be an actual new page or the same page posted back).
Example code you can use to automatically show your loading image (contained in a
div
) when a submit button is clicked is the following:Alternatively, you can use the
UpdatePanel
that comes in the Ajax Toolkit or in ASP.NET 4.0. It has a control calledUpdateProgress
that displays a loading image automatically.EDIT:
I think you mean you want to show a "Loading" image before your first page is even loaded, in which case you should put your master page content wrapped around an
UpdatePanel
, use a progress loader control that automatically shows an image (both available in the Ajax Toolkit or ASP.NET 4.0), and load the substantial (non-master page) content of your page after your initial page load in theUpdatePanel
.You can do this by putting the body of your content page inside a
Panel
, setting the panel's visibility toFalse
, and then setting it toTrue
after the page loads.Markup for an
UpdateProgress
control is as follows. You would, of course, want to style it and position it in the right area.EDIT:
If you don't want to use the
UpdatePanel
andUpdateProgress
controls, then simply do the following:Panel
calledpnlContent
and set the panel's visibility toFalse
.img
and your loading image and put it in a separatePanel
calledpnlLoading
with the visility set toTrue
.Put a client-side script that forces the page to reload as soon as it loads. Put this script inside
pnlLoading
. Update: Put the #3 code below in your ASPX page to create your panel and it will trigger a post back immediately.Add the following #4 code to your
Page_Load
.Code:
For #3:
For #4:
That will cause a loading image to show while your actual page content is being loaded.
我发现以下解决方案在页面导航之间运行良好,不会影响当前的 Ajaxification 或站点结构。
只需将脚本放在母版页上的头部结束标记和正文开始标记之间的无人地带即可。
感谢苏斌的这一期。
http://subinsb.com/loading-bar-until-page -loads-completely-using-javascript
他建议您不要替换变量名称,因为可能存在其他类似的变量,并且代码将无法工作。
如果您想更改加载图像,只需更改变量 subinsblog.style.background 中的背景 URL。
I found the following solution works nicely between page navigations without affecting the current Ajaxification or site structure.
Just drop the script in no-mans-land between the head end and body start tags on your Master page.
Thanks to Subin for this one.
http://subinsb.com/loading-bar-until-page-loads-completely-using-javascript
He recommends you do not replace the variable names, because there might be an other variable like that and the code won't work.
If you want to change the Loading Image just change the background URL in the variable subinsblog.style.background.