具有许多(数百个)CollapsiblePanelExtender 的 ASP.NET 页面的性能问题

发布于 2024-08-30 05:06:44 字数 1525 浏览 5 评论 0原文

我正在维护一个 ASP.NET 站点,用户可以登录该站点来注册一些数据集(用于统计目的)。一个用户注册一组单元的数据,并且为每个单元填写一组表格(每个表格中都有一些字段,但这在这里并不重要)。一种场景是,一个用户有 12 个单元,每个单元中有 25 个表格需要填写,总共 300 个表格。

用于注册这些数据的 ASP.NET 页面按以下方式制作:每个表单都位于一个可以使用 AjaxControlToolkit CollapsiblePanelExtender 折叠的面板中,并且一个单元中的所有表单都位于另一个也可以折叠的面板内。结果是,您有一个类似树视图的结构,单元位于顶部,在每个单元下您可以展开一组表单,并且进一步可以展开每个表单以填充数据(加载页面时所有面板都折叠起来)默认情况下)。

该页面是完全动态生成的(因为表单可以添加到数据库中),为了生成 CollapsiblePanelExtender,我有以下代码:

private CollapsiblePanelExtender GenerateCollapsiblePanelExtender(string id, Panel headerPanel, Panel contentPanel)
{
    CollapsiblePanelExtender collapsiblePanel = new CollapsiblePanelExtender();

    collapsiblePanel.ID = id + ID_COLLAPSIBLE_PANEL_POSTFIX;
    collapsiblePanel.TargetControlID = contentPanel.ID;
    collapsiblePanel.CollapseControlID = headerPanel.ID;
    collapsiblePanel.ExpandControlID = headerPanel.ID;
    collapsiblePanel.Collapsed = true;
    collapsiblePanel.BehaviorID = collapsiblePanel.ID + ID_BEHAVIOUR_POSTFIX;

    return collapsiblePanel;
}

对于一个用户拥有 12 个单元,每个单元有 25 个表单,这意味着总共有 312 个 CollapsiblePanelExtender。正如我所说,默认情况下它们都设置为折叠,但问题是:

当页面加载时,它们似乎都已展开,然后浏览器“开始折叠它们”。然而,这需要非常很长的时间(在 Firefox 中,我什至收到有关无响应脚本的警告,IE 和 Chrome 只需要很长时间,但没有警告)。当所有“折叠”完成后,它可以顺利打开和关闭单个面板,但用户抱怨初始加载速度极慢。

所以我的问题很简单:有没有办法优化它,使加载更顺畅?例如,是否可以最初仅在每个 CollapsiblePanelExtender 中加载标题面板,然后以某种方式异步加载内容面板?

最后澄清一下:
我知道我可以简单地将页面的设计更改为仅包含一个单元,从而大大减小内容的大小,但我希望避免这种情况(用户更喜欢将所有内容都放在一个页面中的方式)。这也意味着对页面逻辑的相当大的改变(是的,我知道 - 那时它的代码库很差)

I'm maintaining an ASP.NET site where users can log on to register some set of data (for statistical purposes). One user registers data for a set of units, and for each of these units a set of forms are to be filled out (with a handful of fields in each form, but that doesn't matter here). One scenario is that a user has 12 units, and in each of these units there is 25 forms to be filled, meaning a total of 300 forms.

The ASP.NET page for registering these data is made the following way: each form is in a panel that can be collapsed using an AjaxControlToolkit CollapsiblePanelExtender, and all forms in a unit is inside another panel that also can be collapsed. The result is that you have a tree view-like structure with the units on the top, and under each unit you can expand a set of forms, and further each form can be expanded to fill data (the page is loaded with all panels collapsed by default).

The page is generated completely dynamically (as forms can be added in a database), and for generating the CollapsiblePanelExtenders I have the following code:

private CollapsiblePanelExtender GenerateCollapsiblePanelExtender(string id, Panel headerPanel, Panel contentPanel)
{
    CollapsiblePanelExtender collapsiblePanel = new CollapsiblePanelExtender();

    collapsiblePanel.ID = id + ID_COLLAPSIBLE_PANEL_POSTFIX;
    collapsiblePanel.TargetControlID = contentPanel.ID;
    collapsiblePanel.CollapseControlID = headerPanel.ID;
    collapsiblePanel.ExpandControlID = headerPanel.ID;
    collapsiblePanel.Collapsed = true;
    collapsiblePanel.BehaviorID = collapsiblePanel.ID + ID_BEHAVIOUR_POSTFIX;

    return collapsiblePanel;
}

With one user having 12 units each with 25 forms, this means a total of 312 CollapsiblePanelExtenders. As I said, they are all set to be collapsed by default, but here's the problem:

When the page loads, they all appear to be expanded, and then the browser "starts collapsing them". This however takes a very long time (in Firefox I even get a warning about an unresponsive script, IE and Chrome only takes forever but without the warning). When all the "collapsing" is complete it works smooth to open and close single panels, but users have complained about the extremely slow initial loading.

So my question is simple: is there a way to optimize this so that the loading goes smoother? Is it for instance possible to only load the header panels in each CollapsiblePanelExtender initially, and then load the content panel asynchronously in some way?

One final clarification:
I know I could simply change the design of the page to only include one unit and thus reducing size of the contents drastically, but I hope to avoid this (users prefer the way with everything in one page). It would also mean a rather large change to the logic of the page (yes, I know - it's a poor code base at that point)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戴着白色围巾的女孩 2024-09-06 05:06:44

在询问了一些其他地方后,我终于成功解决了这个问题。解决方案是完全跳过 CollapsiblePanelExtenders,而是使用 jQuery 来处理折叠/扩展。

在我的结构中,所有标题面板都使用 css 类 HeaderPanel,所有内容面板都使用 css 类 ContentPanel(默认情况下所有这些都是隐藏的)。然后,我可以使用以下脚本来处理所有折叠/展开逻辑:

<script language="javascript">
    $(document).ready(function() {
        $("div.HeaderPanel").toggle(
        function() {
            $(this).next("div.ContentPanel").show("slow");
        },
        function() {
            $(this).next("div.ContentPanel").hide("slow");
        });
    });
</script>

解决方案确实非常简单,而且效果非常好!折叠/扩展比我使用 CollapsiblePanelExtenders 时看起来更加平滑和漂亮,并且页面加载速度也非常快:)

After asking some more around other places, I finally managed to solve this issue. The solution was to skip the CollapsiblePanelExtenders altogether, and instead use jQuery to handle the collapsing/extending.

In my structure, all header panels use the css class HeaderPanel, and all content panels use the css class ContentPanel (all of these are hidden by default). I can then use the following script to handle all the collapse/expand logic:

<script language="javascript">
    $(document).ready(function() {
        $("div.HeaderPanel").toggle(
        function() {
            $(this).next("div.ContentPanel").show("slow");
        },
        function() {
            $(this).next("div.ContentPanel").hide("slow");
        });
    });
</script>

The solution was really quite simple, and it works like a charm! The collapsing/extending is soo much smoother and nicer than what it looked like when I used the CollapsiblePanelExtenders, and the page loads really fast as well :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文