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

  • Home
  • SEARCH
  • 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 page that contains dynamically generated Dropdown List controls and I want
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 page that I am trying to dynamically add some links to.
I have a page that contains an iframe element. I want to have some
I have an aspx page that contains regular html, some uicomponents, and multiple tokens
I have a .jsp that contains an IFrame with a page that has some
I have a page that contains some JS to update the browser history (
I have a page that contains a user control that is just a personalized
I have a page that contains several forms, by submitting each one of them,

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.