2013-07-16 22 views
0

我有用於打開和關閉面板的選項卡。多個標籤/面板可以一次打開。其次是我目前的解決方案:多選項卡/面板控件並不總是正確響應

protected static int[] tabControls = { 0, 0 }; 

protected void Page_Load(object sender, EventArgs e) 
    { 
     if (!IsPostBack) 
     { 
      storyPanel.Visible = true; 
      hoursPanel.Visible = false; 
     } 
    } 

/* ===== TAB CONTROLS ===== */ 
    protected void Tab1_Click(object sender, EventArgs e) 
    { 
     if (tabControls[0] == 1) 
     { 
      storyPanel.Visible = true; 
      Tab1.CssClass = "Clicked"; 
      tabControls[0] = 0; 
      ClientScript.RegisterStartupScript(this.GetType(), "hash", "location.hash = '#storyPostBack';", true); 
     } 
     else 
     { 
      storyPanel.Visible = false; 
      Tab1.CssClass = "Initial"; 
      tabControls[0] = 1; 
     } 
    } 

    protected void Tab2_Click(object sender, EventArgs e) 
    { 
     if (tabControls[1] == 1) 
     { 
      hoursPanel.Visible = true; 
      Tab2.CssClass = "Clicked"; 
      tabControls[1] = 0; 
      ClientScript.RegisterStartupScript(this.GetType(), "hash", "location.hash = '#hoursPostBack';", true); 
     } 
     else 
     { 
      hoursPanel.Visible = false; 
      Tab2.CssClass = "Initial"; 
      tabControls[1] = 1; 
      ClientScript.RegisterStartupScript(this.GetType(), "hash", "location.hash = '#storyPostBack';", true); 
     } 
    } 

有時標籤必須按兩次爲它作出反應,並打開面板,以及收到的CSS變化本身。我無法弄清楚爲什麼。另外,有沒有更好的方法。

編輯:

它實際上是沒有標籤,很抱歉沒有說清楚。這是標籤的幻覺使用按鈕/板/ CSS:

enter image description here

服務器控件:

<table width="80%" align="center"> 
    <tr> 
    <td> 
     <asp:Button Text="Tab 1" BorderStyle="None" ID="Tab1" CssClass="Initial" runat="server" 
      OnClick="Tab1_Click" /> 
     <asp:Button Text="Tab 2" BorderStyle="None" ID="Tab2" CssClass="Initial" runat="server" 
      OnClick="Tab2_Click" /> 
     <asp:Panel ID="storyPanel" runat="server"> 
      <table style="width: 100%; border-width: 1px; border-color: #666; border-style: solid"> 
      <tr> 
       <td> 
       <h3> 
        <span>tab content here </span> 
       </h3> 
       </td> 
      </tr> 
      </table> 
     </asp:Panel> 
     <asp:Panel ID="hoursPanel" runat="server"> 
      <table style="width: 100%; border-width: 1px; border-color: #666; border-style: solid"> 
      <tr> 
       <td> 
       <h3> 
        tab 2 content here 
       </h3> 
       </td> 
      </tr> 
      </table> 
     </asp:Panel> 
</table> 
+0

你用什麼tabControl?請提供您的標記代碼的一些相關部分。 –

回答

1

它看起來對我來說,所有的選項卡的初始狀態是可見的:

protected static int[] tabControls = { 0, 0 }; 

但事實上,只有一個標籤實際上是可見的嗎?還是所有的面板都應該同時顯示?如果您的tabControls變量與面板的實際可見性不同步,則可能需要點擊兩次。一旦將tabControls更改爲不可見,然後再將其更改爲可見。要解決,只需做:

protected static int[] tabControls = { 0, 1 }; 
相關問題