片段缓存asp.net webform中的用户控件主页面
问题描述:
我有一个主页面,它用作边栏进行导航。我为该边栏创建了一个用户控件,因为每个用户都有自己的一组导航菜单。片段缓存asp.net webform中的用户控件主页面
在我的UserMenu里面我使用Infragistic webexplorer和Iam动态地使用ado.net结果创建webexplorer的每个项目。
一切工作正常。在高带宽,但在低带宽需要3-4秒的菜单栏加载。使用户在每次回发等待这么多。
所以,我想片段缓存。但我似乎没有working.can你建议我什么是错
在母版我做
<div>
//this is my usercontrol
<uc1:DynamicMenuBar runat="server" id="DynamicMenuBar" />
</div>
<div id="main" class="content" >
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
<div class="bodybackground">
</div>
</asp:ContentPlaceHolder>
</div>
在我的用户.ASCX
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DynamicMenuBar.ascx.cs" Inherits="ArtWebApp.DynamicMenuBar" %>
<%@ Register assembly="Infragistics35.Web.v12.1, Version=12.1.20121.2236, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" namespace="Infragistics.Web.UI.NavigationControls" tagprefix="ig" %>
<%@ OutputCache Duration="600" VaryByParam="none" %>
<ig:WebExplorerBar ID="WebExplorerBar1" runat="server" Width="250px">
</ig:WebExplorerBar>
而且在我的用户控件.ascx.cs中,我已经完成了以下操作
public partial class DynamicMenuBar : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
loadexplorerebar(); //this function creates the groups and childs based on the database result dynamically
this.WebExplorerBar1.EnableViewState = true;
}
}
答
这似乎是互联网问题。尝试使用AJAX调用而不是服务器代码进行菜单检索
答
即使uc被缓存,我仍然会调用Page_Load。尝试在调用loadexplorerebar()之前检查它是否在缓存中。如果它不在缓存中,它将为空。
所以尝试改变:
if (!IsPostBack)
到:
if (!IsPostBack && WebExplorerBar1 == null)