本文介绍了Ajax 工具包 TabPanel Invisible Tag Bug的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 ajax 控件工具包 TabPanel 时遇到了一个有点奇怪的错误.我有 4 个标签,如下所示:

I have encountered a slightly bizarre bug while using the ajax control toolkit TabPanel. I have 4 tabs in row like so:

[Tab1][Tab2][Tab3][Tab4]

[Tab1][Tab2][Tab3][Tab4]

现在选项卡 2 应该只出现在某些情况下,因此将其可见性设置为 false.然而,虽然它是不可见的,但如果我点击 Tab 3,它会在切换到 Tab 1 之前加载该选项卡.同样选择 tab4 将加载 tab4,然后立即切换到 tab3.在服务器端,ActiveTabChanged 事件被击中两次,一次是针对正确选择的选项卡,一次是针对正在切换的选项卡.

Now tab 2 should only appear in certain circumstances, and so has its visibility set to false. However while it is invisible, if I was to click on Tab 3, it would load the tab before switching to Tab 1. Similarly selecting tab4 will load tab4 but then immediately switch to tab3. On the server side the ActiveTabChanged event is being hit twice, once for the tab correctly selected, on once for the tab it is switching too.

如果我将 Tab2 移到选项卡行的末尾,则一切正常.稍微阅读了工具包后,我认为这是与活动选项卡索引有关的错误,并且 javascript 将其设置为低于应有的值,但我不确定如何修复它.

If I move Tab2 to the end of the row of tabs, everything works fine. Having read up on the toolkit a bit, I presume this is an error to do with the active tab index, and the javascript is setting it to one lower than it should, but I'm not sure how to going about fixing it.

推荐答案

我不确定这是否是同一个问题,但它听起来与我几个月以来遇到的问题相似.在这里查看我的问题和解决方案:

I'm not sure if this is the same issue but it sounds similar to one that i've had for few months. Have a look here for my problem and the solution:

我必须从 PreRender 修复 Ajax-Toolkit 中的一个错误:

I had to fix a Bug in Ajax-Toolkit from PreRender:

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

这篇关于Ajax 工具包 TabPanel Invisible Tag Bug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 13:17