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
            Sizes_Div.Controls.Add(hl)
            Sizes_Div.Controls.Add(hh)

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

            Dim ll As New Label
            ll.Text = "<br>"
            Sizes_Div.Controls.Add(ll)
        Next

Where Sizes_Div is my Panel.

Reading Code (not working)

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

Any one can help me ..
Thanx

Recommended Answers

All 2 Replies

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.