I have able to generate several labels and textboxes based on a table in the database during runtime. My problem is that I could not get these values from these textboxes whenever a user changes these values and update them.

Thank you for any answer or idea.

I am using ASP.NET 2 (VB.NET).

Take a look at this sample.

Sample.aspx

<form id="form1" runat="server">
    <div>
    
    </div>
    </form>

Sample.aspx.vb

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim tx As New TextBox
        tx.ID = "txt1"
        form1.Controls.Add(tx)

        Dim bt As New Button
        bt.Text = "Submit"
        form1.Controls.Add(bt)
        AddHandler bt.Click, AddressOf showit

    End Sub

    Protected Sub showit(ByVal s As Object, ByVal e As EventArgs)
        Dim tx As TextBox = CType(FindControl("txt1"), TextBox)
        Response.Write(tx.Text)
    End Sub

string text=((TextBox)page.findcontrols("runtimeGeneratedTextboxName")).Text

Member Avatar for simongh2

Because the controls are dynamically generated, you need to create them & wire a handler up with every request, even postbacks. You should do this as early as possible, preferably in page_init. This means the page postback handler can figure out what controls need updating with changed values & fire the changed events for those controls.

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.