Dropdown, checkboxlist loses viewstate value

Last post 10-09-2008 5:28 AM by gona. 11 replies.

Sort Posts:

  • Dropdown, checkboxlist loses viewstate value

    09-10-2008, 2:30 PM
    • Member
      point Member
    • msadiqali
    • Member since 07-19-2002, 12:45 PM
    • Posts 8

    Hi,

    I have an Ajax enabled master and child page. In the child page,  I have two drop downs. One is visible and the other hidden. On Item change of first I have to show the second. In page load, if not postback, I am populating the second drop down and hiding it. On selectedindexchange of first I am showing the second drop down but values are not shown. Why is this happening? any idea? also the same issue exists with checkboxlist also.

     what am i doing wrong here? I tried to populate the listbox in index change of first also. it works but when i select it , i am not getting the selected value at all.

    Regards
    Mohamed Sadiq Ali Basheer

    Never doubt that a small group of committed people can change the world. Indeed it is the only thing that ever has.
  • Re: Dropdown, checkboxlist loses viewstate value

    09-10-2008, 3:06 PM
    • All-Star
      28,063 point All-Star
    • bmains
    • Member since 10-22-2004, 12:20 PM
    • Posts 5,655

    Can you post any related code?  So you are definitely wrapping binding code with not Page.IsPostBack, and you don't set EnableViewState="false" on that control or any parent control, right?

    It's hard to tell so seeing the code and markup would help.

    Brian

    "Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
  • Re: Dropdown, checkboxlist loses viewstate value

    09-10-2008, 3:11 PM
    • Member
      point Member
    • msadiqali
    • Member since 07-19-2002, 12:45 PM
    • Posts 8
    <asp:UpdatePanel runat="server" id="UpdSearch" updatemode="Always" EnableViewState=true>

    <ContentTemplate>

    <asp:table id="tblSearchClues" runat=server>

    <asp:TableRow ID="trSave" runat=server Visible=false>

    <asp:TableCell >Do you want to save the search?</asp:TableCell>

    <asp:TableCell ><asp:DropDownList ID="ddlSearchDet" runat="server" OnSelectedIndexChanged="ddlSearchDet_SelectedIndexChanged" AutoPostBack=true EnableViewState=true >

    <asp:ListItem></asp:ListItem>

    <asp:ListItem Value="1" Text="Yes"></asp:ListItem>

    <asp:ListItem Value="0" Text="No"></asp:ListItem>

    </asp:DropDownList>

    </asp:TableCell>

    </asp:TableRow>

    </asp:Table>

     

    <asp:UpdatePanel runat="server" id="updSearchDataEntry" updatemode="Always">

    <ContentTemplate>

    <asp:Panel ID="pnlSearchDetails" runat=server Visible=false EnableViewState=true>

    <table border=0 >

    <tr>

    <td colspan=4><asp:Label ID="lblError" runat=server ForeColor="Red" Visible=false></asp:Label></td>

    </tr>

    <tr>

    <td>Search Name:</td>

    <td colspan=3><asp:TextBox ID="txtSearchName" runat=server Columns=35 EnableViewState=true ></asp:TextBox></td>

    </tr>

    <tr>

    <td>Description:</td>

    <td colspan=3><asp:TextBox ID="txtDescription" runat=server TextMode="MultiLine" Columns=35 Rows=6 EnableViewState=true></asp:TextBox></td>

    </tr>

    <tr>

    <td>Category:</td>

    <td colspan=3><asp:DropDownList ID="ddlCategory" runat="server" OnSelectedIndexChanged="ddlCategory_SelectedIndexChanged" AutoPostBack=true>

    </asp:DropDownList></td>

    </tr>

    <tr>

    <td colspan=4>&nbsp;</td>

    </tr>

    </table>

    </asp:UpdatePanel>

    </asp:UpdatePanel>

    Regards
    Mohamed Sadiq Ali Basheer

    Never doubt that a small group of committed people can change the world. Indeed it is the only thing that ever has.
  • Re: Dropdown, checkboxlist loses viewstate value

    09-10-2008, 3:13 PM
    • Member
      point Member
    • msadiqali
    • Member since 07-19-2002, 12:45 PM
    • Posts 8

    This is how the aspx is constructed..In code behind

    if (!Page.IsPostBack)

    {

    FillDropDown();

    }

     

    Regards
    Mohamed Sadiq Ali Basheer

    Never doubt that a small group of committed people can change the world. Indeed it is the only thing that ever has.
  • Re: Dropdown, checkboxlist loses viewstate value

    09-10-2008, 11:32 PM

    I suggest tru to use CascadingDropDown from AJAXControlToolkit

    CascadingDropDown is an ASP.NET AJAX extender that can be attached to an ASP.NET DropDownList control to get automatic population of a set of DropDownList controls. Each time the selection of one the DropDownList controls changes, the CascadingDropDown makes a call to a specified web service to retrieve the list of values for the next DropDownList in the set.

    http://www.asp.net/AJAX/AjaxControlToolkit/Samples/CascadingDropDown/CascadingDropDown.aspx

     

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: Dropdown, checkboxlist loses viewstate value

    09-11-2008, 12:28 PM
    • All-Star
      28,063 point All-Star
    • bmains
    • Member since 10-22-2004, 12:20 PM
    • Posts 5,655

    Hey,

    You could use that extender yes.  But I think the issue may be that the drop downs are in separate update panels; you have to manually call the Update method on the second update panel to update the UI on that panel, or put everything in one update panel...

    Brian

    "Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
  • Re: Dropdown, checkboxlist loses viewstate value

    09-11-2008, 12:29 PM
    • All-Star
      28,063 point All-Star
    • bmains
    • Member since 10-22-2004, 12:20 PM
    • Posts 5,655

    Oh wait, I didn't see that you were nesting them; try removing the nesting as that's unnecessary...  just try the one and see.  If that doesn't work, post the selectedindexchanged event handler for the first drop down, and let's see what goes on there...

    Brian

    "Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
  • Re: Dropdown, checkboxlist loses viewstate value

    09-11-2008, 2:32 PM
    • Member
      point Member
    • msadiqali
    • Member since 07-19-2002, 12:45 PM
    • Posts 8
    I tried chetans method..It is getting value but the selected value is not available when i go to save.
    Regards
    Mohamed Sadiq Ali Basheer

    Never doubt that a small group of committed people can change the world. Indeed it is the only thing that ever has.
  • Re: Dropdown, checkboxlist loses viewstate value

    09-11-2008, 2:33 PM
    • Member
      point Member
    • msadiqali
    • Member since 07-19-2002, 12:45 PM
    • Posts 8

    I removed the nesting also. as i posted earlier, the selected value is not coming now.

    Regards
    Mohamed Sadiq Ali Basheer

    Never doubt that a small group of committed people can change the world. Indeed it is the only thing that ever has.
  • Re: Dropdown, checkboxlist loses viewstate value

    09-11-2008, 4:37 PM
    • All-Star
      28,063 point All-Star
    • bmains
    • Member since 10-22-2004, 12:20 PM
    • Posts 5,655

    OK, so what does the related code method look like (fill method, selectedindexchanged)?

    Brian

    "Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
  • Re: Dropdown, checkboxlist loses viewstate value

    09-11-2008, 4:41 PM
    • Member
      point Member
    • msadiqali
    • Member since 07-19-2002, 12:45 PM
    • Posts 8

    I have a button. In that click event, I am tracking the dropdown value to save.

    ddlCategory.SelectValue

    Regards
    Mohamed Sadiq Ali Basheer

    Never doubt that a small group of committed people can change the world. Indeed it is the only thing that ever has.
  • Re: Dropdown, checkboxlist loses viewstate value

    10-09-2008, 5:28 AM
    • Member
      2 point Member
    • gona
    • Member since 07-13-2007, 1:36 AM
    • Posts 3

     I am having the same problem. I think when you hide the dropdown box, the viewstate is disabled and is not available after postback. I tested this with textbox and dropdown and it is happening only for dropdown.Can somebody please explain why this is happening and how do i avoid?

    I am creating a dropdown dynamically and I cannot use hiddenfield for a workaround.

    Thanks,

    Gopal

Page 1 of 1 (12 items)