Dropdown list not retaining selected value using Ajax TabControl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • temijojo
    New Member
    • Feb 2009
    • 2

    Dropdown list not retaining selected value using Ajax TabControl

    Hello, Can someone help me in this problem.

    In my content page, I used 2 user controls inside an Ajax Toolkit TabControl. One of the user controls is a data entry with a dropdownlist. The dropdownlist does not retain its selected value when I make a postback (click an update or save button). But when I run it without Tabcontrol, it's ok. Is there anything I should add to the code?

    Here's the aspx script:
    Code:
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
     Runat="Server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
     <act:TabContainer ID="TabPanel1" runat="server" ActiveTabIndex="0"   
            Height="600px" CssClass="ajax__tab_xp" OnActiveTabChanged="TabChanged" AutoPostBack="true">
        <act:TabPanel ID="Panel1" runat="server"  
            HeaderText="Client List" ScrollBars="Auto">
               <ContentTemplate>
               <uc2:uc_ClientGrid ID="uc_ClientGrid1" runat="server" />
               </ContentTemplate>
        </act:TabPanel>
       <act:TabPanel ID="TabPanel2" runat="server" 
            HeaderText="Details" >
               <ContentTemplate>
               <uc1:uc_client_info_insert ID="uc_client_info_insert1" runat="server" />
               </ContentTemplate>
        </act:TabPanel>
      </act:TabContainer>
    </asp:Content>
    
    Here's the user control script:
    <asp:UpdatePanel runat="server">
    <ContentTemplate>
    
        &nbsp;<asp:Panel ID="pnlClientInfo" runat="server"  
            GroupingText="CLIENTS INFO" Width="400px">
        <table id="tblClientInfo" runat="server" class="clientInfo" >
            <tr>
                <td colspan="2">First Name:<br /><asp:TextBox ID="txtFirstname" runat="server" width="98%"></asp:TextBox></td>
            </tr>
            <tr>
                <td colspan="2">Last name:<br /><asp:TextBox ID="txtLastName" runat="server" width="98%"></asp:TextBox></td>
            </tr>
            <tr>
                <td colspan="2" >Address 1:<br /><asp:TextBox ID="txtAddress1" 
                        runat="server" width="98%"></asp:TextBox></td>
            </tr>
            <tr>
                <td colspan="2" >Address 2 :<br /><asp:TextBox ID="txtAddress2" runat="server" width="98%"></asp:TextBox></td>
            </tr>
            <tr>
                <td>City:<br /><asp:TextBox ID="txtCity" runat="server"></asp:TextBox></td>
                <td>Province:<br />
                    <asp:DropDownList ID="cmbProvinces" runat="server"  >
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>Postal Code:<br /><asp:TextBox ID="txtPostalCode" runat="server"></asp:TextBox></td>
                <td>Home Phone:<br /><asp:TextBox ID="txtHomePhone" runat="server"></asp:TextBox></td>
            </tr>
        </table>
        </asp:Panel>
    </div>
    <div id="msgBox" runat="server" style="font-family: Verdana; font-size: medium; color: #FF0000; font-style: italic">
        
    </div>
    
    <div >
        <asp:Button ID="btnInsert" runat="server" Text="New" />
        <asp:Button ID="btnUpdate" runat="server" Text="Edit" />
        <asp:Button ID="btnDelete" runat="server" Text="Delete" />
        <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
    </div>
    </ContentTemplate>
      </asp:UpdatePanel>
    </div>
    Thanks a lot....
    Last edited by pbmods; Feb 7 '09, 07:11 PM. Reason: Added CODE tags.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    This is an interesting problem.
    I placed a DropDownList in a AjaxToolKit Tab Control and discovered the same problem. In fact it's not that it doesn't retain it's selected value, the selection never even makes it to the server!
    Setting the DropDownList's EnableViewState ="true" did not help.

    I'm interested in the solution to this problem.

    Comment

    • dafodil
      Contributor
      • Jul 2007
      • 389

      #3
      Try checking your load event because it seems you are AutoPostBacking .

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        In the load event the selected index remains 0 regardless of selection.

        Comment

        • dafodil
          Contributor
          • Jul 2007
          • 389

          #5
          This is a bug that Microsoft should fix. If you badly need that control then perhaps using sessions could help.

          Comment

          • fasirain
            New Member
            • Mar 2012
            • 1

            #6
            Do this way for MVC ->
            Code:
            <%: Html.DropDownListFor(model => model.Address[0].StateCode, new SelectList((IEnumerable<SelectListItem>)ViewData["StateCode"], "Value", "Text", Model.Address[0].StateCode), "--Select--")%>
            Last edited by Frinavale; Mar 14 '12, 01:00 PM. Reason: Added code tags.

            Comment

            Working...