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 8414323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:08:22+00:00 2026-06-10T01:08:22+00:00

I have a panel with a form that has a drop down list with

  • 0

I have a panel with a form that has a drop down list with values 1-10. When a button on the panel is pressed, that panel is made invisible and a second made visible. On the second panel I have rows of controls being generated dynamically. The number of rows is determined by the selecteditem on the drop down list.

My problem is that when I want to carry out validation and then storing of the values of the contents of controls that are dynamically created, the controls are removed.

I understand this is to do with the lifecycle of the page and the persistence of the dynamically created controls but I have no idea to get round the problem. I have read many other similar questions on here and few have working examples of who to solve this so I am none the wiser. This includes suggestions that the dynamically created controls need to be created on pageload or pageinit, how can this be since we don’t know how many to make?

To recap: these controls are NOT addedd when the page loads, these controls are only added AFTER a user has pressed a button. We don’t know how many controls to make until the user has selected how many they want.

My code so far:

Partial Class View
Inherits SeatPlannerModuleBase
Implements IActionable
Dim valid As String = "success"

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load
    Try

        Dim n As Integer = 0

        ' now, create n TextBoxes, adding them to the PlaceHolder TextBoxesHere
        For i As Integer = 0 To n - 1
            res_Placeholder.Controls.Add(New Label())
            booking_Placeholder.Controls.Add(New Label())

            title_Placeholder.Controls.Add(New TextBox())
            firstname_Placeholder.Controls.Add(New TextBox())
            surname_Placeholder.Controls.Add(New TextBox())
            ticketNum_Placeholder.Controls.Add(New TextBox())

        Next

        ' now, set the Text property of each TextBox
        IterateThroughBooking(Me)
        IterateThroughReservation(Me)
        IterateThroughTitle(Me)
        IterateThroughFirstname(Me)
        IterateThroughSurname(Me)
        IterateThroughTicketNum(Me)

        If Not Page.IsPostBack Then

        End If

    Catch exc As Exception        'Module failed to load
        ProcessModuleLoadException(Me, exc)
    End Try
End Sub

Protected Sub IterateThroughTitle(ByVal parent As Control)
    Dim count As Integer = 1

    For Each c As Control In title_Placeholder.Controls
        If c.[GetType]().ToString().Equals("System.Web.UI.WebControls.TextBox") AndAlso c.ID Is Nothing Then
            'DirectCast(c, TextBox).Text = "TextBox_Title " + count.ToString()
            DirectCast(c, TextBox).ID = "TextBox_Title_" + count.ToString()
            DirectCast(c, TextBox).CssClass = "DYN_TextBox"
            count += 1
        End If

        If c.Controls.Count > 0 Then
            IterateThroughTitle(c)
        End If
    Next
End Sub

Protected Sub CreateTextBoxes()

    Dim n As Integer = number_of_tickets_Ddl.SelectedValue

    ' now, create n TextBoxes, adding them to the PlaceHolder TextBoxesHere
    For i As Integer = 0 To n - 1
        res_Placeholder.Controls.Add(New Label())
        booking_Placeholder.Controls.Add(New Label())

        title_Placeholder.Controls.Add(New TextBox())
        firstname_Placeholder.Controls.Add(New TextBox())
        surname_Placeholder.Controls.Add(New TextBox())
        ticketNum_Placeholder.Controls.Add(New TextBox())

    Next

    ' now, set the Text property of each TextBox
    IterateThroughBooking(Me)
    IterateThroughReservation(Me)
    IterateThroughTitle(Me)
    IterateThroughFirstname(Me)
    IterateThroughSurname(Me)
    IterateThroughTicketNum(Me)

    Retreive_first_row()

End Sub

Protected Sub next_submit_Btn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles next_submit_Btn.Click

    Step1_Pnl.Visible = False
    Step2_Pnl.Visible = True
    CreateTextBoxes()
    Button1.Attributes.Add("OnClick", "validate_step2(); return false;")

End Sub

Protected Sub next_submit2_Btn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles next_submit2_Btn.Click

    step2_error_Lbl.Text = CType(Me.FindControl("TextBox_Title_2"), TextBox).Text

End Sub

End Class       
  • 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. Editorial Team
    Editorial Team
    2026-06-10T01:08:23+00:00Added an answer on June 10, 2026 at 1:08 am

    The dynamic created controls don’t persist after postback, you have to recreate them everytime, it’s a technological restriction. To know how many controls create, you could save a variable in session/viewstate/whatever and if you name them just like the previous state, the viewstate will be recovered though.

    Check these links for more information:

    http://weblogs.asp.net/infinitiesloop/archive/2006/08/25/TRULY-Understanding-Dynamic-Controls-_2800_Part-1_2900_.aspx

    ASP.NET dynamically created controls and Postback

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Form that has a panel with some textBoxes and checkBox that
I have a form that has a panel in it. I've set the panel
I have a form in C# with a drop down box. When that drop
I have a drop down box, each option in it has 2 values. I
I have web form with a panel which has form elements in side it.
I have a panel that has lots of labels and checkboxes. I want to
I have a c# windows form application that has a similar GUI functionality as
I have form on my page that has the following code <form class=form> ...
I have a form that has two views. These views are controlled by radio
I have a form that will multiple Panel controls stacked on top of each

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.