Solved

Drop down items missing after postback

Posted on 2007-11-30
3
446 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
[X]
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
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 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