2012-07-12 49 views
0

我有一個系統管理員選項卡,點擊時會產生大量的AJAX一個tabpanel這是動態的數據庫驅動...如何在我的情況下實現惰性加載?

<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; 
    } 

我想實現延遲加載,所以當系統管理員選項卡單擊只有第一個選項卡數據將加載和不是所有的標籤樣本。我一直在尋找,但我沒有找到任何東西來幫助我與我的情況...任何幫助將不勝感激

+0

我想有人需要提取幾種方法... – ChaosPandion 2012-07-12 13:43:04

+0

可能有用的:http://stackoverflow.com/q/10931064/284240 – 2012-07-12 13:59:31

回答

0

問題是你想要什麼不適用於webforms。至少不會這樣。您可能想嘗試使用多視圖控件。並且,可能會動態地將視圖添加到多視圖中,但它們都需要創建每個請求以使視圖在webforms中正常運行。

我也嘗試將UI細節封裝到webusercontrols(ascx)中並動態加載用戶控件。這樣,您可以在設計時保留大部分佈局,而不是運行時。

+1

這是不正確的。您可以輕鬆地延遲加載TabPanel。你只需要把它們包裝在UserControls中,並且只在需要的時候加載它們(不是從page_load隱式地,而是通過來自TabContainer的'ActiveTabChanged'事件處理程序的'bindData'方法)。這裏有一個類似的問題對我的回答:http://stackoverflow.com/a/10931323/284240 – 2012-07-12 13:48:35

+0

所以它可能,但不直觀:)我仍然會避免它因爲這個原因。維護和調試變得更加困難。 – 2012-07-12 13:51:03

+0

一旦你知道它是如何工作的,它並不比ASP.NET中的其他任何東西更困難:) – 2012-07-12 13:55:10

相關問題