2011-05-17 59 views
6

我在使用ajax控件工具包TabPanel時遇到了一個輕微的奇怪的錯誤。我有4個選項卡行,像這樣:Ajax Tookit TabPanel隱形標籤錯誤

[TAB1] [TAB2] [TAB3] [TAB4]

現在選項卡應該只出現在某些情況下,所以有它的可見性設置爲false。然而,雖然它是不可見的,但如果我點擊Tab 3,它會在切換到Tab 1之前加載標籤。同樣地,選擇Tab4將加載Tab4,但是然後立即切換到Tab3。在服務器端,ActiveTabChanged事件被命中兩次,一次爲正確選擇的標籤,一次爲它正在切換的標籤。

如果我將Tab2移動到標籤行的末尾,一切正常。在閱讀了一下這個工具包之後,我認爲這對於活動標籤索引是一個錯誤,並且javascript將它設置爲低於它的值,但我不知道如何去修復它。

回答

3

我不確定這是否是相同的問題,但它聽起來類似於我已經有幾個月。看看這裏我的問題和解決方案:

我不得不從固定在的PreRender Ajax的工具包一個Bug:

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender 
    'ensure that the Tabs stay invisible that have Visible=False on markup and dont get visible programmatically' 
    Me.TabThatShouldStayInvisible.Visible = False 
    FixTabPanelVisible(TabContainer1) 
End Sub 

Protected Sub FixTabPanelVisible(ByVal tabcontainer As AjaxControlToolkit.TabContainer) 
    For Each tp As AjaxControlToolkit.TabPanel In tabcontainer.Tabs 
     Dim oldVisible As Boolean = CBool(IIf(IsNothing(ViewState(tp.UniqueID + "_Display")), True, ViewState(tp.UniqueID + "_Display"))) 
     If Not tp.Visible Then 
      ViewState(tp.UniqueID + "_Display") = False 
      DisableTab(tabcontainer, tabcontainer.Tabs.IndexOf(tp)) 
     ElseIf tp.Visible AndAlso Not oldVisible Then 
      ViewState(tp.UniqueID + "_Display") = True 
      EnableTab(tabcontainer, tabcontainer.Tabs.IndexOf(tp)) 
     End If 
     tp.Visible = True 
    Next 
    Dim fixScript As New StringBuilder() 
    fixScript.Append("function DisableTab(container, index) {$get(container.get_tabs()[index].get_id() + ""_tab"").style.display = ""none"";}") 
    fixScript.Append("function EnableTab(container, index) {$get(container.get_tabs()[index].get_id() + ""_tab"").style.display = """";}") 
    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "FixScriptReg", fixScript.ToString(), True) 
End Sub 

Protected Sub EnableTab(ByVal container As AjaxControlToolkit.TabContainer, ByVal index As Integer) 
    Dim sFunction As String = "function() {EnableTab($find('" & container.ClientID & "')," & index & ");}" 
    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "EnableTabFun" & index, "Sys.Application.add_load(" & sFunction & ");", True) 
End Sub 

Protected Sub DisableTab(ByVal container As AjaxControlToolkit.TabContainer, ByVal index As Integer) 
    Dim sFunction As String = "function() {DisableTab($find('" & container.ClientID & "')," & index & ");}" 
    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "DisableTabFun" & index, "Sys.Application.add_load(" & sFunction & ");", True) 
End Sub