make sure you have autopostback set to True
thanks :-)
I have attached a very simple sample of some ASP.NET files that are causing me problems. Inside the ZIP is a cut-down version of a dynamic custom control and an implementing ASP.NET page.
If I put a dropdown list inside the custom control, when it first loads, items are added to the dropdown. After postback, these items are lost. ViewState appears not to be loaded for the dropdown inside the panel.
The panel is added to the custom control's Controls collection, in the CreateChildControls override. I have also tried adding the panel in OnInit, OnLoad, LoadViewState and TrackViewState. All do the same thing and lose the items.
I want to know why ViewState is not loaded for the dropdown inside the panel. I've struggled for over three hours with this now...
J.
PS: I've had to rename all the files in the ZIP to .txt to get around the overly-sensitive extention check on the attachments facility -- remove the .txt extention and import the files into a VS2005 Web App Project.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Romasa; the lists are only supposed to populate their items on first load, then cache them into ViewState for subsequent page loads. This works normally (see lst1) but not for the one in the panel (see lst2).
meispisces; AutoPostback is set to true. Not that this should make any difference. Items are supposed to be retained in ViewState, regardless of whether a list calls __doPostback as part of its onchange event.
I think I have worked this out. It just seems that I can't overload Controls to return a ControlCollection from one of my child controls. It would render correctly but postbacks are all messed up.
I rewrote the control to render the elements manually, overriding the RenderStartTag and RenderEndTag methods and it has worked ever since.
Obviously this is the 'correct' way to write a control but I was hoping to perform a couple of shortcuts and it looks like I can't.
J.
Business Accounts
Answer for Membership
by: RomasaPosted on 2009-09-08 at 22:21:42ID: 25288446
That is creating problem because aspx.cs page call it refreshes all object so
on page load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lst1.Items.Add("test1");
lst1.Items.Add("test2");
lst1.Items.Add("test3");
lst2.Items.Add("test1");
lst2.Items.Add("test2");
lst2.Items.Add("test3");
}
}
}
U can add it in aspx page or
call it on other event like on binding