简体   繁体   English

如何在asp.net中加载页面时添加Ajax加载器?

[英]How to add Ajax loader in while loading the page in asp.net?

I want to use an ajax loader while loading the page with transparent background. 我想在加载具有透明背景的页面时使用ajax加载器。 I tried the following code which displays the loading image but how to cover whole backgroung as transperent. 我尝试了下面的代码,显示加载图像,但如何覆盖整个背景文本作为transperent。 My code is: 我的代码是:

<div class="UpdateProgress1">
<asp:UpdateProgress ID="UpdateProgress1" runat="server" DynamicLayout="true">
<ProgressTemplate>
    <img src="image/ajax-loader.gif"  /> Loading ...
</ProgressTemplate>
</asp:UpdateProgress>
</div>

And my css is: 我的css是:

.UpdateProgress1 {
 color:#fff;
 position:fixed;
 filter:alpha(opacity=50);
 -moz-opacity:0.5;
 -khtml-opacity: 0.5;
 opacity: 0.5;
 vertical-align: middle;
 text-align: center;
 background-color: #000;
 float: left;
 top:18%;
 left:13%;
 width:73%; 
 }

If anyone knows any link or any solution please tell me. 如果有人知道任何链接或任何解决方案,请告诉我。 and in the above css if i add the height property the image get displayed at the page load time without click event. 并在上面的CSS中,如果我添加高度属性,图像将在页面加载时显示,而不会发生单击事件。 thank you. 谢谢。

To clarify, which of the following are you trying to do: 为了澄清,您要尝试执行以下哪项操作:

1) Load a page and, when the user invokes a post-back, display a loader while waiting for the post-back. 1)加载页面,当用户调用回发时,在等待回发时显示加载器。 2) Display a loader at the beginning of the page that's actually loading. 2)在实际加载的页面开头显示加载器。

From the description, it sounds like the latter. 从描述中,它听起来像后者。 If so, this is a very uncommon approach. 如果是这样,这是一种非常罕见的方法。 Depending on the page content, it can be difficult to know when it's truly "done loading." 根据页面内容,可能很难知道它何时真正“完成加载”。 For an HTML/Javascript setup, your best bet would probably be: 对于HTML / Javascript设置,您最好的选择可能是:

  $(document).ready(function() {
    // code to hide the loader animation
  });

(Note that you'll need jQuery for this, if you don't have it already.) (请注意,如果您还没有jQuery,则需要jQuery。)

Things can get much more complicated if you have content that's delayed for other reasons though, such as waiting for a loaded script to do something or waiting for a browser plugin (such as Flash). 如果您的内容因其他原因而延迟,例如等待加载的脚本执行某些操作或等待浏览器插件(例如Flash),则事情会变得复杂得多。

You appear to have a typo in your HTML: 您的HTML中似乎有拼写错误:

<div id="wrappe">
---- Whole code goes here ----
</div>

This should be called "wrapper". 这应该被称为“包装器”。

Your JavaScript is throwing an error because document.getElementById("wrapper") is returning null, which doesn't have a property style. 您的JavaScript引发错误,因为document.getElementById("wrapper")返回null,它没有属性样式。

What browser are you testing this in? 您正在测试哪种浏览器? You should be seeing a little yellow warning icon in the bottom left of IE's window that will give you some clue that there's a script error. 你应该在IE窗口的左下方看到一个小黄色警告图标,它会给你一些线索错误的线索。

Webpage error details 网页错误详情

Message: Object required 消息:需要对象
Line: 34 行:34
Char: 13 查尔:13
Code: 0 代码:0
URI: http://localhost:64888/ImageTest.aspx URI: http:// localhost:64888 / ImageTest.aspx

If you are using Firefox, get yourself a copy of the Developer Toolbar which will give you a nice red exclamation mark and the exact error from JavaScript: 如果您使用的是Firefox,请自行获取开发人员工具栏的副本,它会为您提供一个漂亮的红色感叹号以及来自JavaScript的确切错误:

Error: document.getElementById("wrapper") is null 错误:document.getElementById(“wrapper”)为null
Source File: http://localhost:64888/ImageTest.aspx 源文件: http:// localhost:64888 / ImageTest.aspx
Line: 34 行:34

Use an Iframe with an higher z-index to block the main page. 使用具有更高z-index的Iframe来阻止主页面。

<iframe id="blockPage" src="about:blank" style="display: none; position: absolute;
        z-index: 10; filter: Alpha(Opacity=40) DropShadow(Color=#454545);"></iframe>

Use the following functions to show and hide the frame 使用以下功能显示和隐藏框架

function BlockPageContent()
{
    var ifrm = document.getElementById("blockPage");
    if(null != ifrm)
    {
        ifrm.style.display = "block";
        ifrm.style.top = 0;
        ifrm.style.left =0;
        ifrm.style.width=screen.availWidth;
        ifrm.style.height = screen.availHeight; 
    }
}

function ShowPageContent()
{
    var ifrm = document.getElementById("blockPage");
    if(null!= ifrm && ifrm.style.display != "none")
    {
        ifrm.style.display = "none";
    }
}

and call the above function in the following fashion. 并以下列方式调用上述函数。

Call BlockPageContent in "InitializeRequest" and ShowPageContent in "EndRequest". 在“EndizeRequest”中调用BlockPageContent,在“EndRequest”中调用ShowPageContent。 "InitializeRequest" and "EndRequest" are eventhandlers of PageRequestManager object. “InitializeRequest”和“EndRequest”是PageRequestManager对象的事件处理程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM