【问题标题】:How to implement Lazy Load in my situation?如何在我的情况下实施延迟加载?
【发布时间】:2012-07-12 13:40:22
【问题描述】:

我有一个系统管理员选项卡,点击后会生成很多动态和数据库驱动的 ajax 选项卡面板......

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
<ajaxToolkit:TabContainer ID="TabContainer1" runat="server" Width="100%" ActiveTabIndex="0"
    CssClass="ajax__tab_header">
    <ajaxToolkit:TabPanel ID="TPAdjCal" Width="100%" runat="server">
        <HeaderTemplate>
            <img runat="server" id="imgAdjCalendarleft" visible="false" alt="" src="../images/Tabs/GreenLeftBottom.gif" /><asp:Button
                ID="imgAdjCalendar" BorderStyle="none" Text="" CssClass="MainTabs"
                runat="server"></asp:Button><img alt="" src="../images/Tabs/GreenRightBottom.gif"
                    runat="server" id="imgAdjCalendarright" visible="false" />
        </HeaderTemplate>
        <ContentTemplate>
            <table class="HeaderCaption" id="Table1" cellspacing="0" cellpadding="3" width="100%"
                border="0" runat="server">
                <tr class="PagerRow">
                    <td>
                        <asp:Label ID="HeaderLabel1" runat="server" Text="Label"></asp:Label>
                        <asp:Label ID="FunctionCode1" runat="server" Text="" Visible="false"></asp:Label>
                    </td>
                    <td>
                    </td>
                    <td>
                    </td>
                </tr>
            </table>
        </ContentTemplate>
    </ajaxToolkit:TabPanel>
    <ajaxToolkit:TabPanel ID="TabContainer2" Width="100%" runat="server">
        <HeaderTemplate>
            <img runat="server" id="imgPoliceReportsleft" visible="false" alt="" src="../images/Tabs/GreenLeftBottom.gif" /><asp:Button
                ID="imgPoliceReports" BorderStyle="none" Text="" CssClass="MainTabs"
                runat="server"></asp:Button><img alt="" src="../images/Tabs/GreenRightBottom.gif"
                    runat="server" id="imgPoliceReportsright" visible="false" />
        </HeaderTemplate>
        <ContentTemplate>
            <table class="HeaderCaption" id="Table2" cellspacing="0" cellpadding="3" width="100%"
                border="0" runat="server">
                <tr class="PagerRow">
                    <td>
                        <asp:Label ID="HeaderLabel2" runat="server" Text="Label"></asp:Label>
                        <asp:Label ID="FunctionCode2" runat="server" Text="" Visible="false"></asp:Label>
                    </td>
                    <td>
                    </td>
                    <td>
                    </td>
                </tr>
            </table>
        </ContentTemplate>
    </ajaxToolkit:TabPanel>
 </ajaxToolkit:TabContainer>

代码隐藏:当单击系统管理员选项卡时,我调用一个加载选项卡的 loadmanager 方法.. 示例如下

      protected void LoadManagerTabs(bool runFirstLoad)
        {
       if (Session["UserSystemTabs"] == null)
          {
     postMessage("You do not have access to any system functions", Constants.ERROR_MSG,false);
        return;
    }

    string[,] functions = Session["UserSystemTabs"] as string[,];

    functions.GetLength(0);
    if (functions.GetLength(0) > 0)
    {
        string funccode = functions[0, 0];
        if (funccode.Length > 0)
        {
            if (isHaveAccess(funccode))
            {
                string pagename = DBUtils.getFuncUrlByCode(funccode);
                try
                {
                    eClaim.Controls.Tables.DataTables contr = null;
                    contr = (eClaim.Controls.Tables.DataTables)LoadControl("~/" + pagename + ".ascx");
                    contr.Key = "";
                    contr.runPageLoad = runFirstLoad;

                    contr.FuncCode = funccode;
                    TPAdjCal.Controls.Add(contr);
                    TPAdjCal.Visible = true;
                    imgAdjCalendar.Text = functions[0, 1];
                    HeaderLabel1.Text = functions[0, 1];
                    FunctionCode1.Text = functions[0, 0];
                    //imgAdjCalendar.Visible = true;
                }
                catch
                {
                    DataTablesV2 contr = null;
                    contr = (DataTablesV2)LoadControl("~/" + pagename + ".ascx");
                    contr.Key = "";
                    //contr.runPageLoad = runFirstLoad;

                    if (ShouldRunPageLoad(funccode) && TabContainer1.ActiveTabIndex.Equals(0))
                    {
                        contr.runPageLoad = true;
                    }
                    else
                    {
                        contr.runPageLoad = false;
                    }

                    contr.FuncCode = funccode;
                    TPAdjCal.Controls.Add(contr);
                    TPAdjCal.Visible = true;
                    imgAdjCalendar.Text = functions[0, 1];
                    HeaderLabel1.Text = functions[0, 1];
                    FunctionCode1.Text = functions[0, 0];
                    //imgAdjCalendar.Visible = true;
                }

                if (TabContainer1.ActiveTabIndex.Equals(0))
                {
                    imgAdjCalendar.CssClass = "MainTabsSelected";
                    imgAdjCalendarleft.Src = "../images/Tabs/LightGreenLeftBottom.gif";
                    imgAdjCalendarright.Src = "../images/Tabs/LightGreenRightBottom.gif";
                }
                else
                {
                    imgAdjCalendar.CssClass = "MainTabs";
                    imgAdjCalendarleft.Src = "../images/Tabs/GreenLeftBottom.gif";
                    imgAdjCalendarright.Src = "../images/Tabs/GreenRightBottom.gif";
                }
            }
            else
            {
                TPAdjCal.Visible = true;
                imgAdjCalendar.Visible = false;
                imgAdjCalendarleft.Visible = false;
                imgAdjCalendarright.Visible = false;
            }
        }
    }
    else
    {
        TPAdjCal.Visible = true;
        imgAdjCalendar.Visible = false;
        imgAdjCalendarleft.Visible = false;
        imgAdjCalendarright.Visible = false;
        imgTabScrollright.Visible = false;
        btnTabScroll.Visible = false;
        imgTabScrollleft.Visible = false;
    }

    if (functions.GetLength(0) > 1)
    {
        string funccode = functions[1, 0];
        if (funccode.Length > 0)
        {
            if (isHaveAccess(funccode))
            {
                string pagename = DBUtils.getFuncUrlByCode(funccode);
                try
                {
                    eClaim.Controls.Tables.DataTables contr = null;
                    contr = (eClaim.Controls.Tables.DataTables)LoadControl("~/" + pagename + ".ascx");
                    contr.Key = "";
                    contr.runPageLoad = runFirstLoad;
                    contr.FuncCode = funccode;
                    TabContainer2.Controls.Add(contr);
                    TabContainer2.Visible = true;
                    imgPoliceReports.Text = functions[1, 1];
                    HeaderLabel2.Text = functions[1, 1];
                    FunctionCode2.Text = functions[1, 0];
                    //imgPoliceReports.Visible = true;
                }
                catch
                {
                    DataTablesV2 contr = null;
                    contr = (DataTablesV2)LoadControl("~/" + pagename + ".ascx");
                    contr.Key = "";
                    contr.runPageLoad = runFirstLoad;
                    contr.FuncCode = funccode;
                    TabContainer2.Controls.Add(contr);
                    TabContainer2.Visible = true;
                    imgPoliceReports.Text = functions[1, 1];
                    HeaderLabel2.Text = functions[1, 1];
                    FunctionCode2.Text = functions[1, 0];
                    //imgPoliceReports.Visible = true;
                }

                if (TabContainer1.ActiveTabIndex.Equals(1))
                {
                    imgPoliceReports.CssClass = "MainTabsSelected";
                    imgPoliceReportsleft.Src = "../images/Tabs/LightGreenLeftBottom.gif";
                    imgPoliceReportsright.Src = "../images/Tabs/LightGreenRightBottom.gif";
                }
                else
                {
                    imgPoliceReports.CssClass = "MainTabs";
                    imgPoliceReportsleft.Src = "../images/Tabs/GreenLeftBottom.gif";
                    imgPoliceReportsright.Src = "../images/Tabs/GreenRightBottom.gif";
                }
            }
            else
            {
                TabContainer2.Visible = true;
                imgPoliceReports.Visible = false;
                imgPoliceReportsleft.Visible = false;
                imgPoliceReportsright.Visible = false;
            }
        }
    }
    else
    {
        TabContainer2.Visible = true;
        imgPoliceReports.Visible = false;
        imgPoliceReportsleft.Visible = false;
        imgPoliceReportsright.Visible = false;
        imgTabScrollright.Visible = false;
        btnTabScroll.Visible = false;
         imgTabScrollleft.Visible = false;
    }

我正在尝试实现延迟加载,因此当单击系统管理员选项卡时,只会加载第一个选项卡数据,而不是所有选项卡。我一直在寻找,但我没有找到任何可以帮助我解决我的情况...任何帮助将不胜感激

【问题讨论】:

标签: asp.net asp.net-ajax lazy-loading ajaxcontroltoolkit


【解决方案1】:

问题是您想要的内容不适用于网络表单。至少不是这样。您可能想尝试使用多视图控件。并且,可能会动态地向多视图添加视图,但它们都需要在每次请求时创建,以便视图在 web 表单中正常运行。

我还会尝试将 UI 细节封装到 webusercontrols (ascx) 中并动态加载用户控件。这样您就可以将大部分布局保留在设计时,而不是运行时。

【讨论】:

  • 这不是真的。您可以轻松地延迟加载 TabPanel。您只需将它们包装在 UserControls 中并仅在需要时加载它们(不是从 page_load 隐式加载,而是通过 TabContainer 的 ActiveTabChanged 事件处理程序中的自定义 bindData 方法)。这是我的一个类似问题的回答:stackoverflow.com/a/10931323/284240
  • 所以它是可能的,但不直观:) 仅出于这个原因,我仍然会避免它。维护和调试变得更加困难。
  • 一旦你知道它是如何工作的,它并不比 ASP.NET 中的其他任何东西更难:)
  • 你的意思是 WebForms。 ASP.Net 是直截了当的并坚持 http。 WebForms 很复杂。
  • ASP.NET 只是技术。所以 WebForms、MVC 或其他什么都是 ASP.NET。但是,是的,这个问题是关于WebForms
猜你喜欢
  • 1970-01-01
  • 2017-01-04
  • 1970-01-01
  • 2019-09-26
  • 2012-07-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多