0

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

4
Contributors
3
Replies
6
Views
6 Years
Discussion Span
Last Post by simongh2
0

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
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.