Question

I have a site that uses a couple DropDownLists that are databound. I was also doing the traditional if (!IsPostBack) {list.Databind();} and relied on viewstate to keep the lists filled during a post back. I recently converted the site to ASP.NET 3.5 and noticed that the lists are empty during postback (as if ViewState is disabled). I didn't explicitly disable anything, and am wondering if anyone has seen a similar change or behavior in their viewstate dependent controls.

Thanks!

James

Was it helpful?

Solution

I have definitely seen similar problems (though mine were with visibility). Try to ensure that the ViewState is explicitly enabled on the whole control hierarchy down to the dropdown.

e.g.

‹asp:Page EnableViewState="True" ...›
     ...

     ‹asp:Panel EnableViewState="True"...›
         ...
         ‹asp:DropDownList EnableViewState="True" ...›
         ...
      ...
...

R.

OTHER TIPS

This snippet pasted into the troublesome page is a quick way to see where viewstate is enabled/disabled.

<%
Control c = <YourMisbehavingControlNameHere>;

while ( c != null )
{
    Response.Write( c.GetType().Name + " = " + c.EnableViewState.ToString() + "<br/>" );

    c = c.Parent;
}

%>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top