显示在ASP.Net Ajax中为长时间运行的进程加载映像/进度条

时间:2011-03-19 10:53:09

标签: c# asp.net ajax long-running-processes

如何在ASP.Net Ajax应用程序中执行长时间运行的进程时为用户显示加载图像?除了使用页面方法之外还有其他方法吗?有什么想法吗?

1 个答案:

答案 0 :(得分:2)

在客户端,您可以连接Sys.WebForms.PageRequestManager BeginRequest:

<script type="text/javascript" language="javascript">
                Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
                Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
                function BeginRequestHandler(sender, args)
                {
                     var elem = args.get_postBackElement();
                     ActivateAlertDiv('visible', 'AlertDiv', elem.value + ' processing...');
                }
                function EndRequestHandler(sender, args)
                {
                     ActivateAlertDiv('hidden', 'AlertDiv', '');
                }
                function ActivateAlertDiv(visstring, elem, msg)
                {
                     var adiv = $get(elem);
                     adiv.style.visibility = visstring;
                     adiv.innerHTML = msg;                     
                }
            </script>

更多信息:http://msdn.microsoft.com/en-us/library/bb397432.aspx