troubleshooting Question

How to get the text property from a dynamically created text box

Avatar of louise001
louise001 asked on
ASP.NET.NET Programming
14 Comments1 Solution281 ViewsLast Modified:
Hello,

In my web application users click a button to confirm selection from a drop-down list, and using the selection my code displays revenue figures in an html table and adds dynamically created text boxes to the table which should take input from users. Ideally I'd like to allow users to enter or update figures in any number of text boxes without a postback for each edit, then update the database and postback in the click event of another button.

My problem is that I can't get at the text property of the dynamically created text box. In the attached code the event txtEditRevenueTextChanged doesn't run at all.

I'm using VB and .Net Framework 4.0.

Thanks for any help.

Louise


' This is the textchanged event handler for the dynamically created text box and when I change the text and then move off the text box it doesn't execute.

 Protected Sub txtTest_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTest.TextChanged

        Dim s As String = txtTest.Text
        Me.ViewState.Add("strTest", s)


    End Sub

Open in new window

' This is what runs when the button to confirm time period selection is clicked, all works fine and the data is displayed as intended.

 For i As Integer = 0 To tDirectors.Rows.Count - 1

                Dim row_data As New TableRow()
                'row_data.ID = tDirectors.Rows(i)("DirectorID").ToString

                'Dim cell_director_id As New TableCell
                'cell_director_id.Text = tDirectors.Rows(i)("DirectorID")
                'row_data.Cells.Add(cell_director_id)

                Dim cell_name As New TableCell
                cell_name.ID = "DirectorID:" + tDirectors.Rows(i)("DirectorID").ToString
                cell_name.Text = tDirectors.Rows(i)("Director")
                row_data.Cells.Add(cell_name)

For int As Integer = 0 To tMonths.Rows.Count

                    If int < tMonths.Rows.Count Then

                        dvRevenues.RowFilter =
                            "(DirectorID = " & tDirectors.Rows(i)("DirectorID") & ") and (MonthID = " & tMonths.Rows(int)("id").ToString & ") or " &
                            "(DirectorID = 0) and (MonthID = " & tMonths.Rows(int)("id").ToString & ")"

                        For Each row As DataRowView In dvRevenues
                            'cells to show revenues and when applicable a text box for editing the revenue amount
                            Dim cell_revenue As New TableCell
                            'cell_revenue.ID = row("DirectorID").ToString & " " & row("MonthID").ToString
                            If tMonths.Rows(int)("id") = row("MonthID") Then
                                If Not row("Closed") Then
                                    Dim txtEditRevenue As New TextBox()
                                    'txtEditRevenue.AutoPostBack = True
                                    If row("DirectorID") <> 0 Then
                                        txtEditRevenue.ID = "DirectorID:" + row("DirectorID").ToString & "MonthID:" & row("MonthID").ToString
                                        txtEditRevenue.Text = row("Revenue").ToString
                                        Dim dtRow As DataRow = dt.NewRow()
                                        dtRow("MonthID") = row("MonthID")
                                        dtRow("DirectorID") = row("DirectorID")
                                        dtRow("Revenue") = row("Revenue")
                                        dt.Rows.Add(dtRow)
                                    ElseIf row("DirectorID") = 0 Then
                                        txtEditRevenue.ID = cell_name.ID + "MonthID:" + row("MonthID").ToString
                                    End If
                                    txtEditRevenue.Width = 50
                                    cell_revenue.Controls.Add(txtEditRevenue)
                                    AddHandler txtEditRevenue.TextChanged, AddressOf txtEditRevenueTextChanged
                                ElseIf row("Closed") Then
                                    cell_revenue.Text = row("Revenue").ToString
                                End If
                            End If
                            row_data.Cells.Add(cell_revenue)
                        Next

Next
Next

Open in new window

ASKER CERTIFIED SOLUTION
tbsolutions

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 14 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros