?
Solved

Drop down items missing after postback

Posted on 2007-11-30
3
Medium Priority
?
450 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:Munawar Hussain
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:
Munawar Hussain earned 1500 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

719 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