Switched to ASP.NET 3.5, DropDownList doesn't remember dynamically added items

女生的网名这么多〃 提交于 2019-12-24 04:41:13

问题


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


回答1:


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.




回答2:


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;
}

%>


来源:https://stackoverflow.com/questions/445222/switched-to-asp-net-3-5-dropdownlist-doesnt-remember-dynamically-added-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!