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

Ask A Question

Stats

  • Questions 71k
  • Answers 71k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Ant is already installed correctly if you're getting this: Buildfile:… May 11, 2026 at 1:23 pm
  • added an answer If you want the test runs to start in the… May 11, 2026 at 1:23 pm
  • added an answer No, .obj files do not support animation. You can check… May 11, 2026 at 1:23 pm

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.