ASP.NET 3.5:在Page_Load期间显示的UpdateProgress() [英] ASP.NET 3.5: Display UpdateProgress during Page_Load()

查看:191
本文介绍了ASP.NET 3.5:在Page_Load期间显示的UpdateProgress()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Visual Studio 2008,并有期待这样的页面构建ASP.NET网站(东西剪断)

I am building an ASP.NET site using Visual Studio 2008 and have a page looking like this (stuff snipped)

<asp:Content ID="Content2" ContentPlaceHolderID="PageContentPlaceHolder" runat="server">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            the page here..
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:UpdateProgress ID="UpdateProgress1" runat="server" DisplayAfter="100">
        <ProgressTemplate>
            <div>
                <asp:Image ID="AjaxImage" runat="server" ImageUrl="Ajax.gif" />
            </div>
        </ProgressTemplate>
    </asp:UpdateProgress>
</asp:Content>

在Page_Load启动长(> 5秒)过程

The page_load starts a long (>5s) process

protected void Page_Load(object sender, EventArgs e)
{            
  if (!IsPostBack)            
  {
    LongRunningProcess();                
  }
}

我怎么能显示的UpdateProgress的LongRunningProcess运行时?它的工作当我移动LongRunningProcess()调用到一个按钮的onclick处理程序。

How can I display the UpdateProgress while the LongRunningProcess is running? It does work when I move the LongRunningProcess() call to a button onclick handler.

推荐答案

创建一个正常的div显示Ajax.gif所以它显示处理的默认。

Create a normal div that shows the Ajax.gif so it shows "processing" by default.

在JavaScript的页面加载()函数,拨打电话回页使用Ajax的PageMethods。

In the javascript pageLoad() function, make a call back to the page using Ajax's PageMethods.

   function pageLoad(sender, args) {
                PageMethods.getVersions(LoadVersionsCallback);
    }

你在.aspx.cs文件调用的方法必须是静态的,它可以带参数,看起来是这样的:

The method you are calling in your .aspx.cs file has to be static, it can take parameters and looks something like:

   [System.Web.Services.WebMethod]
    public static string getVersions()
    {
      StringBuilder sb = new StringBuilder();
       ... etc.
      return sb.ToString();

    }

您在调用该方法完成时该方法将运行指定的JavaScript函数。它将被传递的结果。在这个函数结束时,您隐藏Ajax.gif DIV。

The javascript function that you specified when you called the method will run when the method completes. It will be passed the results. At the end of this function you hide the Ajax.gif div.

   function LoadVersionsCallback(result) {
    // do something with the results - I load a dropdown list box.

   ...etc. 
    // here is where you hide your div holding the Ajax.gif  

   }

然后你就做什么是你正在做的不到1秒的运行....工作

And then you work on making whatever it is you are doing run in less than 1 second....

这篇关于ASP.NET 3.5:在Page_Load期间显示的UpdateProgress()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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