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).

Recommended Answers

All 3 Replies

Take a look at this sample.


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


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

        Dim bt As New Button
        bt.Text = "Submit"
        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)
    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.