我陷入了 UpdatePanel 陷阱

发布于 2024-07-25 18:18:40 字数 385 浏览 1 评论 0原文

我有一个很大的问题。 我正在 ASP.NET 3.5 中制作 CRM(客户关系管理)系统,

我的整个项目基于 DevExpress.com 控件和 UpdatePanels 的使用。

现在,我的一个页面是整个系统的中心页面,包含大量的可能性,因此包含大量的用户控件。

现在我的问题是,它变得非常非常慢,因为 UpdatePanel 正在重新发布整个页面,而不仅仅是更新面板。 我们在弹出窗口出现前 3-4 秒进行交谈:(

有什么方法可以在不伤我脖子的情况下重构整个系统,使其远离 UpdatePanels 吗? 我是否可以优化 UpdatePanels 的使用?

ViewState 也绝对是巨大的。

有什么好的想法欢迎提出...

I have a very big problem. I am making a CRM (Costumer Relationship Management) System in ASP.NET 3.5

I have based my entire project on DevExpress.com controls and the use of UpdatePanels.

Now one of my pages, which is a central page in the whole system, contains a very big amount of possibilities and therefore a big amount of UserControls.

Now my problem is that it's getting really really slow because of the fact that UpdatePanels are reposting the entire page and not only the update panel. We are talking sometime 3-4 seconds before a popup window appears :(

Is there any way I can refactor this entire system away from UpdatePanels without breaking my neck?
Are there anyway I can optimize my use of UpdatePanels?

The ViewState is also absolutely giant.

Any good ideas are welcome...

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

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

发布评论

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

评论(5

浪漫人生路 2024-08-01 18:18:40

无法使用 UpdatePanels 发布整个页面。 我会尝试以下几件事来代替重新设计应用程序:

  1. 禁用任何不需要它的控件的视图状态
  2. 为用户控件设置 UpdateMode="Conditional"。 这不会绕过发布整个页面,但会稍微减少渲染时间。 只有特定 UpdatePanel 的内容才会在浏览器中更新。
  3. 确保您的用户控件具有短 ID。 如果您有很多服务器控件,则 ASP.NET Webforms 在 html 中命名控件的方式这些 ID 会重复很多次。 命名母版页占位符也是如此。 我曾经通过重命名用户控件和占位符将一个大页面切成一半大小。

There's no way to get around posting the entire page using UpdatePanels. In lieu of redesigning the app here are a couple things I'd try:

  1. Disable viewstate for any controls that don't need it
  2. Set the UpdateMode="Conditional" for your user controls. This won't get around posting the entire page but it will cut down on rendering time a little. Only the content for the specific UpdatePanel will be updated in the browser.
  3. Make sure your user controls have short IDs. The way ASP.NET webforms names controls in the html these IDs get repeated quite a bit if you have a lot of server controls. Same goes for naming master page placeholders. I once cut a large page to half the size by renaming user controls and placeholders.
享受孤独 2024-08-01 18:18:40

由于您是 DevExpress 用户,您可能会考虑花一点时间来学习他们的 CallbackPanel< /a> 这将允许您进行异步处理,而无需 UpdatePanel 的开销。

或者(如果我错了,请有人纠正我),但如果所有回发都是异步的(即在 UpdatePanel 中),那么理论上是否可以禁用整个页面的 ViewState(在Page 指令)没有负面后果? 当然,你必须完全测试它,但值得一试。

Since you're a DevExpress user, you might consider taking a little time to learn their CallbackPanel which will allow you to do asynchronous processing without the overhead of the UpdatePanel.

Alternatively (someone please correct me if I'm wrong) but if all of the postbacks are asynchronous (i.e. in an UpdatePanel), wouldn't it be theoretically possible to disable ViewState for the entire page (in the Page directive) without negative consequences? You'd have to test it completely off course, but it's worth a shot.

女中豪杰 2024-08-01 18:18:40

您必须将更新面板中包含的一些回发替换为真正的 AJAX 调用,即将操作所需的数据发送到服务器并仅返回更新视图需要什么,摆脱回发和 UpdatePanels。

(您会注意到我使用了“操作”和“视图”这两个术语 - 是的,我是 MVC 粉丝。您所处的情况是典型的使用 WebForms 和 ASP.NET AJAX 控件很容易陷入的混乱情况.)

You'll have to replace some of the postbacks contained in your update panels with real AJAX calls, i.e. send only the data that is required for the action to the server and get back only what's required to update the view, getting rid of the postback and the UpdatePanels.

(You'll notice my use of the terms 'action' and 'view' - yes, I am an MVC fan. The situation you are in is typical of the mess that is easily got into using WebForms and the ASP.NET AJAX controls.)

眼眸印温柔 2024-08-01 18:18:40
  • 我一定是错过了什么。 为什么你的更新面板正在重新加载整个页面。 更新面板的目的是仅刷新该面板中的内容,不是吗?谢谢您的解释。 我想我们正在讨论重新发布页面而不是像我想象的那样重新绘制面板。

  • 尝试关闭 ViewState,尤其是网格。

  • 您的页面上最常见哪种控件? 尝试用您自己的不使用 ViewState 或 ControlState 的轻量级 UserControl 或 Server Control 替换它们
  • I must be missing something. Why is your updatepanel is reloading the entire page. The point of an updatepanel is to refresh only what is in that panel, isn't it? Thanks for the explanation. I guess we're talking about reposting the page and not redrawing the panel as I thought.

  • Try turning off ViewState, especially for grids.

  • What kind of control is most common on your page? Try replacing those with your own lightweight UserControl or Server Control that does not use ViewState or ControlState
只是我以为 2024-08-01 18:18:40

对于所有感兴趣的人,我想添加一个有关如何删除客户端上的 Viewstate 数据的解决方案。 它确实给服务器带来了额外的负载,但如果您处于与我相同的情况并且拥有大量服务器功能并且需要承担客户端的负载,那么这很好。

让您的所有页面都从 BasePage.cs 派生,如下所示

public class BasePage : System.Web.UI.Page
{
    protected override void SavePageStateToPersistenceMedium(object viewState)
    {
        string vsKey = String.Format("VIEWSTATE_{0}_{1}_{2}", base.Session.SessionID, Request.RawUrl, DateTime.Now);
        Session.Add(vsKey, viewState);
        ClientScript.RegisterHiddenField("__VIEWSTATE_KEY", vsKey);
    }

    protected override object LoadPageStateFromPersistenceMedium()
    {
        string vsKey = Request.Form["__VIEWSTATE_KEY"];
        return Session[vsKey];
    }
}

现在您拥有了视图状态数据会话的密钥,而不是代码中的视图状态...

对于我来说,在每天有 1000-1200 名访客的网站上,这就像一个魅力。

For all Interested I want to add a solution on how to get rid of the Viewstate data on clientside. It does give the server an extra load but if you are in the same situation as me and have a lot of server power and need to take the load of the clientside this is nice.

Let all your pages Derive from BasePage.cs looking like this

public class BasePage : System.Web.UI.Page
{
    protected override void SavePageStateToPersistenceMedium(object viewState)
    {
        string vsKey = String.Format("VIEWSTATE_{0}_{1}_{2}", base.Session.SessionID, Request.RawUrl, DateTime.Now);
        Session.Add(vsKey, viewState);
        ClientScript.RegisterHiddenField("__VIEWSTATE_KEY", vsKey);
    }

    protected override object LoadPageStateFromPersistenceMedium()
    {
        string vsKey = Request.Form["__VIEWSTATE_KEY"];
        return Session[vsKey];
    }
}

Now you have a key to the viewstate data session instead of the viewstate in your code...

Works like a charm for me on a website with 1000-1200 daily visitors as well.

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