Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Drop down items missing after postback

Posted on 2007-11-30
3
442 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

856 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