允许显示.aspx页面中.ASCX控制完成加载之前? [英] Allow .ASPX page to display before .ASCX control finishes loading?

查看:322
本文介绍了允许显示.aspx页面中.ASCX控制完成加载之前?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有它一个控制(的.ascx)的ASP.NET页面。页面(的.aspx)的onload分配一些文本的一对夫妇的标签,并将产品ID到的.ascx控制。该控制的.ascx,onload事件,需要该产品ID从.aspx页和访问数据库几次,确实几种计算,等等 - 基本上需要很长的时间来加载。

I have an ASP.NET page with one control (.ascx) on it. The page (.aspx) onload assigns some text to a couple labels and passes a product ID to the .ascx control. The .ascx control, onload, takes that product ID from the .aspx page and hits the database several times, does several calculations, etc - basically takes a long time to load.

所以,当我点击一个链接到该.aspx页面中,它正在采取7-10秒的页面加载。我已经把范围缩小到了计算上的.ascx控制是罪魁祸首,我已经优化了code作为尽我所能...但它仍然太长。

So when I'm clicking a link to this .aspx page, it is taking 7-10 seconds for the page to load. I've narrowed it down to the calculations on the .ascx control being the culprit and I've optimized the code as much as I can ... but it's still taking too long.

有没有办法来加载.aspx页面中的控件加载过吗? (也许显示正在加载...动画?在使用的UpdateProgress一样?)

Is there a way to load the .aspx page BEFORE the control loads? (Maybe display a "Loading..." animation? Like used in an UpdateProgress?)

推荐答案

您可以用一个UpdatePanel做到这一点。这将需要一些挂羊头卖狗肉,但尝试这样的:

You could do this with an UpdatePanel. It will take a little trickery, but try something like this:

1)将用户控件的UpdatePanel

2)把公共财产上的用户控件像 IsEnabled 它将使用有条件地什么也不做,呈现一个请稍候。将它从你的主页假的。

2) Put a public property on your usercontrol like IsEnabled that it will use to conditionally do nothing or render a "please wait." Set it false from your main page.

3)添加在的OnInit 约code到你的主页:

3) Add some code in OnInit to your main page:

if (MyScriptManager.IsInAsyncPostback) {
    MyUserControl.IsEnabled=true;
}

4)沿着这些路线添加客户端脚本:

4) Add a client script along these lines:

finished=false;
Sys.WebForms.PageRequestManager.pageLoaded(function(sender,args) {
    if (!finished) {
      finished=true;
      __doPostBack('','');
      // you can include the uniqueID of your updatepanel as the first arg 
     // otherwise it will refresh all update panels
    }
});

或使用jQuery ..

or with jquery..

finished=false;
$(document).ready(function() {
   if (!finished) {...
   }
});

这是什么应该做的是会导致立即在页面加载完成后,发起了一个异步回发,这将反过来导致更新面板被刷新。既然你设置当它在异步回发就被启用,它将使自己的第二次。

What this should do is cause an async postback to be initiated immediately after the page is done loading, which will in turn cause the update panel to be refreshed. Since you set it to be enabled when it's in an async postback, it will render itself the 2nd time.

这篇关于允许显示.aspx页面中.ASCX控制完成加载之前?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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