Solved

Drop down items missing after postback

Posted on 2007-11-30
3
434 Views
Last Modified: 2013-12-16
This sounds like a dumb questions even as I am writing it, but I am adding items to a drop down list in the OnLoad.  The dropdown has autopost back enabled.  When I run it the app on the webserver and change the year in the drop down list the items I added dynamically disappear.  When I am debugging, they don't disapper.

<asp:DropDownList ID="ddlYears" runat="server" AutoPostBack="true">
        </asp:DropDownList>

'Populate ddlYears
            For i As Int32 = DateTime.Now.Year - 1 To (DateTime.Now.Year + 2)

                Dim ddlEntry As New ListItem(i.ToString(), i.ToString())
                If i = DateTime.Now.Year Then
                    ddlEntry.Selected = True
                End If
                ddlYears.Items.Insert(ddlYears.Items.Count, ddlEntry)
            Next
0
Comment
Question by:smcdrc
  • 2
3 Comments
 
LVL 12

Expert Comment

by:needo_jee
ID: 20385446
FIRST make sure you it is inside postback

if (!isPostback)
{
populate here
}

2nd check ViewState it should be enabled

 <asp:DropDownList ID="DropDownList1" EnableViewState="true"  runat="server">
        </asp:DropDownList>
0
 
LVL 2

Author Comment

by:smcdrc
ID: 20398181
It is in the !isPostBack and viewstate is enabled.  These are dynamically entered at run time.  
0
 
LVL 12

Accepted Solution

by:
needo_jee earned 500 total points
ID: 20401508
Even you add Items at runtime / dynamically .. does not matter.it should keep items saved. the only condition where it could lost items is .. if you are filling dropdownlist javascrip at client side then during postback you will most likely lose items.
Is it possible to post same code (ASPX + CS) ? I may check that?
Thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now