Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 160135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:58:53+00:00 2026-05-11T10:58:53+00:00

I have a page that contains some dynamically created controls (TextBox and DropDownList). When

  • 0

I have a page that contains some dynamically created controls (TextBox and DropDownList). When a postback occurs, the TextBoxes keep their values, but the DropDownLists lose their ListItems. This is quite confusing, since the page level DropDownList also keeps its ListItems. Can anyone see what’s wrong with the code below?

Any help in solving this issue would be greatly appreciated.

<%@ Page Language='VB'%>  <script runat='server'>   Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs)     If Not Page.IsPostBack Then       ddlFixed.Items.Add(New ListItem('12', '13'))       ddlFixed.Items.Add(New ListItem('14', '15'))     End If     Dim i As Integer     For i = 0 To 3       Dim ddl As New DropDownList       ddl.ID = 'ddlPage' & i       ddl.EnableViewState = True       If Not Page.IsPostBack Then         ddl.Items.Add(New ListItem('12', '13'))         ddl.Items.Add(New ListItem('14', '15'))       End If       pnlDynamic.Controls.Add(ddl)       Dim txtBx As New TextBox       txtBx.ID = 'txtPage' & i       If Not Page.IsPostBack Then         txtBx.Text = 'Preset'       End If       pnlDynamic.Controls.Add(txtBx)     Next   End Sub </script>   <html xmlns='http://www.w3.org/1999/xhtml'> <head runat='server'>   <title></title> </head> <body>   <form id='form1' runat='server' enableviewstate='true'>   <div>     <br />     <br />     <a href='Default.aspx'>Get-Request</a>     <br />     <br />     <asp:Panel runat='server' ID='pnlDynamic' EnableViewState='true' />         <br />     <br />     <asp:DropDownList runat='server' ID='ddlFixed' />     <asp:Button runat='server' ID='btn' Text='Postback'/>   </div>   </form> </body> </html> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:58:53+00:00Added an answer on May 11, 2026 at 10:58 am

    I have found the solution that will allow me to keep the viewstate across postbacks. It’s to call TrackViewState of the ItemCollection.

    CType(ddl.Items, IStateManager).TrackViewState() 

    Thanks to all for your help.

    This is the working solution:

    <%@ Page Language='VB'%>  <script runat='server'>   Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs)     If Not Page.IsPostBack Then       ddlFixed.Items.Add(New ListItem('12', '13'))       ddlFixed.Items.Add(New ListItem('14', '15'))     End If     Dim i As Integer     For i = 0 To 3       Dim ddl As New DropDownList       ddl.ID = 'ddlPage' & i       CType(ddl.Items, IStateManager).TrackViewState()       If Not Page.IsPostBack Then         ddl.Items.Add(New ListItem('12', '13'))         ddl.Items.Add(New ListItem('14', '15'))       End If       pnlDynamic.Controls.Add(ddl)       Dim txtBx As New TextBox       txtBx.ID = 'txtPage' & i       If Not Page.IsPostBack Then         txtBx.Text = 'Preset'       End If       pnlDynamic.Controls.Add(txtBx)     Next   End Sub </script>   <html xmlns='http://www.w3.org/1999/xhtml'> <head id='Head1' runat='server'>   <title></title> </head> <body>   <form id='form1' runat='server' >   <div>     <br />     <br />     <a href='Default.aspx'>Get-Request</a>     <br />     <br />     <asp:Panel runat='server' ID='pnlDynamic' />         <br />     <br />     <asp:DropDownList runat='server' ID='ddlFixed' />     <asp:Button runat='server' ID='btn' Text='Postback'/>   </div>   </form> </body> </html> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ASPX Page that contains several user controls, which are loaded dynamically
I have a view using a master page that contains some javascript that needs
I have a jsf page that contains some javascript includes. And I want to
I have a page that contains a user control that is just a personalized
In a web application, I have a page that contains a DIV that has
I have a master page that contains an ASP.NET server side Menu control (System.Web.UI.WebControls.Menu)
I would like to have an aspx page that contains something like.... <form id=form1
I have an ASP.Net 2.0 page that contains two UpdatePanels. The first panel contains
I have a page P1 loading from site S1 which contains an iframe. That
Here's the problem....I have three components...A Page that contains a User Control and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.