asp.net – Ajax Tookit TabPanel Invisible Tag Bug

前端之家收集整理的这篇文章主要介绍了asp.net – Ajax Tookit TabPanel Invisible Tag Bug前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在使用ajax控件工具包TabPanel时遇到了一个有点奇怪的错误.我有4个标签,如下所示:

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

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

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

解决方法

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

> forums.asp.net: hiding TabContainer TabPanels

我不得不在PreRender的Ajax-Toolkit中修复一个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,"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 & "'),"DisableTabFun" & index,True)
End Sub
原文链接:https://www.f2er.com/aspnet/251605.html

猜你在找的asp.Net相关文章