简体   繁体   English

在页面加载时显示加载进度图像(未提交事件)

[英]Display loading progress image when Page Loads (not submit event)

I need to display loading GIF image while page is loading or during postbacks using jQuery and JavaScript for long running tasks or processes which require significant amount of time to execute. 对于需要长时间运行的任务或进程,我需要在页面加载期间或使用jQuery和JavaScript回发期间显示加载的GIF图像。

I tried this solution, I don't have error but the loading not show. 我尝试了此解决方案,但没有错误,但加载未显示。

My code below. 我的代码如下。

I would greatly appreciate any help you can give me in working this problem. 我将非常感谢您在解决此问题方面可以给我的任何帮助。

.cs .cs

protected void Page_Load(object sender, EventArgs e)
{
    string script = "$(document).ready(function ());";
    ClientScript.RegisterStartupScript(this.GetType(), "load", script, true);
    System.Threading.Thread.Sleep(5000);
    ExportToXLSFunction(); 
}

.aspx .aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="getData.aspx.cs" Inherits="getData"
    EnableEventValidation="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="/jquery/js/jquery.min.js"></script>
    <script type="text/javascript">
        function ShowProgress() {
            setTimeout(function () {
                var modal = $('<div />');
                modal.addClass("modal");
                $('body').append(modal);
                var loading = $(".loading");
                loading.show();
                var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
                var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
                loading.css({ top: top, left: left });
            }, 200);
        }

        ShowProgress();

    </script>
    <style type="text/css">
        .modal
        {
            position: fixed;
            top: 0;
            left: 0;
            background-color: black;
            z-index: 99;
            opacity: 0.8;
            filter: alpha(opacity=80);
            -moz-opacity: 0.8;
            min-height: 100%;
            width: 100%;
        }
        .loading
        {
            font-family: Arial;
            font-size: 10pt;
            border: 5px solid #67CFF5;
            width: 200px;
            height: 100px;
            display: none;
            position: fixed;
            background-color: White;
            z-index: 999;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="loading" align="center">
        Loading. Please wait.<br />
        <br />
        <img src="/images/wait01.gif" alt="" />
    </div>
    </form>
</body>
</html>

use ajaxStart() and ajaxStop() 使用ajaxStart()ajaxStop()

/**on ajaxStart when process start it comes in this event**/
$( document ).ajaxStart(function() {
  $( ".loading" ).show();
});

/**on ajaxStop when process stop it comes in this event**/
$( document ).ajaxStop(function() {
  $( ".loading" ).hide();
});

Have a look at the fiddler 看看提琴手

http://jsfiddle.net/VpDUG/4952/ http://jsfiddle.net/VpDUG/4952/

.modal {
    display:    none;
    position:   fixed;
    z-index:    1000;
    top:        0;
    left:       0;
    height:     100%;
    width:      100%;
    background: rgba( 255, 255, 255, .8 ) 
                url('http://sampsonresume.com/labs/pIkfp.gif') 
                50% 50% 
                no-repeat;
}

here is the nice explanation..you will love it. 这是一个很好的解释..你会喜欢的。

How can I create a "Please Wait, Loading..." animation using jQuery? 如何使用jQuery创建“请稍候,正在加载...”动画?

I tried it, its working super. 我尝试了,它的工作超级。

Thanks to @Jonathan Sampson 感谢@Jonathan Sampson

Some tweak for basic submit or ASP.NET post back. 对基本提交或ASP.NET回发进行一些调整。

function doModal(callback) {
 jQuery("body").addClass("loading");
 window.setTimeout(callback, 100);
}
jQuery(document).ready(function () {
 // Override __doPostBack()
 if (typeof(__doPostBack) != "undefined") {
  var dp = __doPostBack;
  __doPostBack = function () {
   var args = arguments;
   doModal(function () {
    dp.apply(dp, args);
   });
  };
 }
 jQuery('input[type="submit"]').click(function (ev) {
  doModal(function () { });
 });
});

The callback is not really needed, sorry :) 回调不是真正需要的,对不起:)

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

相关问题 在页面加载或使用 ASP.Net 进行 PostBack 时显示加载进度图像 - Display loading progress image when Page Loads or does PostBack using ASP.Net 如何显示加载屏幕图像,直到重定向的页面完全加载? - How to display a loading screen image until the redirected page loads fully? 页面加载或正在进行某些后台进程时的进度条(动画GIF图像):: - progress bar(animated GIF image) when page loads or some background process is going on:: 页面加载时的进度指示器 - Progress indicator while page loads 加载asp.net页面时显示进度图像 - show progress image while loading asp.net page jQuery函数执行时如何显示加载进度条? - How to display a loading progress bar when jQuery function is executing? 提交时在同一页面上显示成功消息 - Display Success message on the same page when submit 在MVC - 4中加载页面时是否可以显示验证错误(带模型验证) - Is it possible to Display validation errors when page loads in MVC - 4 (with model validations) 页面加载时发生NullReferenceException - NullReferenceException when page Loads 如何在等待 MVC 调用返回时为新选项卡显示加载图像或进度条? - How can I display a loading image, or a progress bar, for a new tab while waiting for the MVC call to return?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM