简体   繁体   中英

How To Loading Web User Controls Asynchronously

In my default.aspx page I have many user controls and they take a lot of time to load. any one know how to make this page to be loaded faster.

Be sure to only load the information you need to display on the page on the initial load. Any subsequent information should be loaded via a postback or ajax.

A few days ago somebody asked somewhat similar i tried to answer:

Panel and User Controls vs load User Controls dynamically

Summary:

You should lazy-load your UserControls if you have them all in page but only single UserControls visible. That means:

Do nothing in the UserControl's Page_Load but only when the controller(page) makes it visible. Therefore expose functions to load their data and update their inner UpdatePanels in the ascx. Then - after the function was called from the page and the control was made visible - let the page update the outer UpdatePanel around the UserControl(s).

On this way the usercontrols will neither be rendered nor databound before they have been made visible and you can always simply reference them directly.

Let them communicate in the following ways:

  • Page > UserControl via Functions/Properties
  • UserControl > Page via Events

Because the default page is loaded very often, you could try output cache to improve the performance of your site. You can use it for the whole page or for the user controls that take the longest to load. Just put the following tag on the top of your page

<%@ OutputCache Duration="300" VaryByParam="none" %>

Duration is the time in seconds the page stays in cache.

To improve the performance of your site you should first analyze the bottlenecks and provide us with more information. There are many possiblities for performance improvements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM