Hi all
I was in need to add controls dynamically to a apanel , I did that.
The problem when i want to read their values . I can't do that

Adding code

For i = 1 To count
            Dim uu As New Unit(50)
            Dim hl As New Label
            Dim h2 As New Label

            Dim hh As New TextBox
            hl.Text = "Height:"
            hh.ID = "H" & i
            hh.Text = hh.ID

            hh.MaxLength = 3
            hh.Columns = 10
            hh.Width = uu

            Dim ww As New TextBox
            h2.Text = "Width"
            ww.ID = "W" & i
            ww.MaxLength = 3
            ww.Columns = 10
            ww.Width = uu

            Dim ll As New Label
            ll.Text = "<br>"

Where Sizes_Div is my Panel.

Reading Code (not working)

Dim b As TextBox = CType(Sizes_Div.FindControl("H1"), TextBox)

Any one can help me ..

Controls added dynamically to panels won't be saved in the viewstate during postbacks. So if you want to get your dynamic control values, you have to populate the panel on EACH postaback, not only on the first page hit.

Ofcourse, you should not set the dynamic control values on postbacks, doing so will overwrite the submited values.

Hope this is helpful!

This article has been dead for over six months. Start a new discussion instead.