DropDownList viewstate does not work

S

SevDer

Hi,

I have 1 parent user control and 4 child user controls inside that.
the last user control has problems with viewstate.
I have 4 dropdowns in this user control where I bind them from code behind
as follows:

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
BindStaticControls();
}//end if
}//end Page_Load method

private void BindStaticControls()
{
//Billing state dropdown
ddState.DataSource = statesDataTable;
ddState.DataTextField = "StateName";
ddState.DataValueField = "StateCode";
ddState.DataBind();

//Shipping state dropdown
ddSState.DataSource = statesDataTable;
ddSState.DataTextField = "StateName";
ddSState.DataValueField = "StateCode";
ddSState.DataBind();

//Billing country dropdown
ddCountry.DataSource = countriesDataTable;
ddCountry.DataTextField = "CountryName";
ddCountry.DataValueField= "CountryCode";
ddCountry.DataBind();
ddCountry.EnableViewState = true;

}

1. In a postback all the content of these dropdowns are lost.
2. In ascx page for testing, for some of them I put explicit attriubtes as
in the following code lines

Example1: <asp:DropDownList id="ddSCountry" CssClass="lit"
runat="server" DataSource='<%# countriesDataTable %>'
DataValueField="CountryCode" DataTextField="CountryName"></asp:DropDownList>

Example2:
<asp:DropDownList id="ddCountry" CssClass="lit" runat="server"
EnableViewState="True"></asp:DropDownList>

Example3:
<asp:DropDownList id="ddSState" CssClass="lit"
runat="server"></asp:DropDownList>

And in the trace, the viewstate size for these dropdowns are always 0. So I
cannot set the viewstate for it. And I really don't know why!

As you will see from the code behind code, I explicitly enable viewstate too
but it doesn't help as the others.

So for the last step I extended my approach to set enableViewState="True" in
<%@ Control> tag

This problem drove me crazy for the last 4 hours and I and my friends cannot
find a solution for this.

Please help ASAP, or I will go crazy.

Best regards,
SevDer
 
M

Mike Dando

I have the same problem. I have the same problem with a ListBox in that the
items added at runtime are
not restored with the default ViewState handling. I guess I will have to
code this myself to save/restore
the ListBox items ?

Mike.
 
S

SevDer

Mike said:
I have the same problem. I have the same problem with a ListBox in that the
items added at runtime are
not restored with the default ViewState handling. I guess I will have to
code this myself to save/restore
the ListBox items ?

Mike.
Hi Mike,

Actually I found the problem I have.
May be you have a similar problem.
My dropdowns were in a panel, and my panel's viewstate was disabled.
After enabling viewstate of the panel, it started to work.

as a first step, try to move your dropdown to the end or begining of the
form, may be you have a similar problem. If it doesn't work, send me an
email with more details.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,068
Latest member
MakersCBDIngredients

Latest Threads

Top