locked
Bugs in TabContainer and Accordion RRS feed

  • Question

  • User-1028990472 posted

    I'm not sure this is the correct place to post this, but I've found some glaring bugs in both the TabContainer and Accordion controls.
    I did not notice this before until I decided to put more than 1 DropDownList in a TabContainer with AutoPostBack="true"

    Create a form, add a TabContainer and add a TabPanel.
    Inside the TabPanel, add 3 dropdownLists (w/some dummy data) in the ContentTemplate
    Set AutoPostBack="true" on the controls.
    On the code behind, create 3 event handlers for the SelectedIndexChanged events.
    Put a break point on each of the 3 subs.

    Run the page.

    Make a selection from 1 of the dropDownLists:
    The codebehind breakpoint for that DropDownList fires once, the first time it loads.
    Now, step through the debugger til the page is refreshed again.
    Now, go to a different dropDownList and make a selection.
    - the page posts back a second time, but now, not only does the DropDownList you just changed SelectedIndexChanged event fire, but the PREVIOUS one you selected ALSO fires!
    - Now change the selection of the 3rd DropDownList, and you will find that the other 2 DropDownLists will fire their SelectedIndexChanged events (even though they are not selected!).

    The Accordion control has the same (extra event firing) problem.

       <ajaxToolkit:TabContainer ID="tc1" runat="server" ActiveTabIndex="0" CssClass="TabStyles" Width="560px" EnableViewState="False">
            <ajaxToolkit:TabPanel ID="tp1" runat="server">
                <HeaderTemplate>tab 1</HeaderTemplate>
                <ContentTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
                        <asp:ListItem>1</asp:ListItem>
                        <asp:ListItem>2</asp:ListItem>
                        <asp:ListItem>3</asp:ListItem>
                    </asp:DropDownList>
                    <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True">
                        <asp:ListItem>A</asp:ListItem>
                        <asp:ListItem>B</asp:ListItem>
                        <asp:ListItem>C</asp:ListItem>
                    </asp:DropDownList>
                    <asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="True">
                        <asp:ListItem>alpha</asp:ListItem>
                        <asp:ListItem>beta</asp:ListItem>
                        <asp:ListItem>gamma</asp:ListItem>
                    </asp:DropDownList>
                </ContentTemplate>
            </ajaxToolkit:TabPanel>
        </ajaxToolkit:TabContainer>

        Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
    
        End Sub
    
        Protected Sub DropDownList2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList2.SelectedIndexChanged
    
        End Sub
    
        Protected Sub DropDownList3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList3.SelectedIndexChanged
    
        End Sub

    I've spent 2 days trying different settings (ViewState on/off, using UpdatePanels, etc, etc.), but could not find any workaround for this.

    Wednesday, October 16, 2013 9:49 PM

Answers

  • User-417640953 posted

    <ajaxToolkit:TabContainer ID="tc1" runat="server" ActiveTabIndex="0" CssClass="TabStyles" Width="560px" EnableViewState="False">
    

    Hi mc9000,

    I'm glad to you post issue to asp.net forum.

    Based on your description and code provided, I see that if the dropdownlist selected item is not the initial item, once page post back, event

    SelectedIndexChanged will be fired. As we know that if ViewState is disabled on the page or  on the DropDownList control, the  selected index

    cannot be saved, so  each postback looks like the selected  index has been changed. In above code, I see you set the EnableViewState of TabContainer as false.

    So the three dropdownlist's selected index cannot be saved and it will appear the scenes you descibed. Please set the property EnableViewState of TabContainer as true.

    Then try it again. Thanks.

     

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 18, 2013 1:33 AM

All replies

  • User-1716253493 posted

    Do you call ddl databind() every postback in page_load event?

    Wednesday, October 16, 2013 10:12 PM
  • User-1028990472 posted

    no databinding is going on - just pre-filled values

    I discovered that the real bug is with ASP.NET and not those control containers.
    It happens when any one of the DropDownLists has EnableViewState="false", but you have to make selections via AutoPostBack a couple of times to see the bug.
    Basically, if the first DDL has EnableViewState="false" and was previously selected (and POSTed back), then you make a selection with a different DDL, the DDL (with EnableViewState="false") will fire its SelectedIndexChanged event as well (I think maybe because the control is being re-initialized).

    See this code:

    <asp:DropDownList ID="DropDownList1" runat="server" EnableViewState="false" AutoPostBack="True">
                        <asp:ListItem>1</asp:ListItem>
                        <asp:ListItem>2</asp:ListItem>
                        <asp:ListItem>3</asp:ListItem>
                    </asp:DropDownList>
                    <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True">
                        <asp:ListItem>A</asp:ListItem>
                        <asp:ListItem>B</asp:ListItem>
                        <asp:ListItem>C</asp:ListItem>
                    </asp:DropDownList>
                    <asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="true">
                        <asp:ListItem>alpha</asp:ListItem>
                        <asp:ListItem>beta</asp:ListItem>
                        <asp:ListItem>gamma</asp:ListItem>
                    </asp:DropDownList>

    My biggest problem is that I have a situation where the first DropDownList's ViewState has to be disabled to avoid a different error.

    Code behind - nothing much but break points on the Subs.

    Public Class TestPage2
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        End Sub
    
        Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
    
        End Sub
    
        Protected Sub DropDownList2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList2.SelectedIndexChanged
    
        End Sub
    
        Protected Sub DropDownList3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList3.SelectedIndexChanged
    
        End Sub
    
    End Class

    Wednesday, October 16, 2013 10:36 PM
  • Thursday, October 17, 2013 12:11 AM
  • User-417640953 posted

    <ajaxToolkit:TabContainer ID="tc1" runat="server" ActiveTabIndex="0" CssClass="TabStyles" Width="560px" EnableViewState="False">
    

    Hi mc9000,

    I'm glad to you post issue to asp.net forum.

    Based on your description and code provided, I see that if the dropdownlist selected item is not the initial item, once page post back, event

    SelectedIndexChanged will be fired. As we know that if ViewState is disabled on the page or  on the DropDownList control, the  selected index

    cannot be saved, so  each postback looks like the selected  index has been changed. In above code, I see you set the EnableViewState of TabContainer as false.

    So the three dropdownlist's selected index cannot be saved and it will appear the scenes you descibed. Please set the property EnableViewState of TabContainer as true.

    Then try it again. Thanks.

     

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 18, 2013 1:33 AM