how to reach a control in a dynamically extended HTML Table

B

buran

Dear ASP.NET Programmers,

I have a HTML table (running as server control with the control ID:
tblInsertSP). The table has 16 rows with textboxes. Depending on the value
of the ddlSPType, which is a dropdownlist control on the page, I add
dynamically extra rows to the table. For instance, if the ddlSPType selected
item is Aviation Company, an extra row containing a cell with the textbox
control txtAircrafts is added to the HTML table tblInsertSP (which now has
17 controls). I use the following code:

Dim k, totalRowCount as Int16

Select Case ddlSPType.SelectedValue

Case 1

Dim tRow As New HtmlTableRow
For k = 0 to To 2
tRow.Cells.Add(New HtmlTableCell)
Next

totalRowCount = tblInsertSP.Rows.Count

tblInsertSP.Rows(totalRowCount - 1).Cells(0).InnerText = "Aircrafts"

Dim txtAircrafts As New TextBox
tblInsertSP.Rows(totalRowCount -
1).Cells(1).Controls.Add(txtAircrafts)

Case 2

....

End Select


After adding extra rows dynamically, I want to save the entered information
into the database tables, SP and SPAviationCompany (the latter is used for
specific data of the SP, namely Aircrafts). I have to reach the txtAircrafts
control in the dynamically added row. I tried it with the following code but
it did not work:


Dim str As String
str = CType(Page.FindControl("tblInsertSP").FindControl("txtAircrafts"),
TextBox).Text

I receive an error stating that there's no such an object. How can I reach
this object? Thanks in advance.

Burak
 
E

Elton Wang

It seems VS.2003 doesn't fully support controls
dynamically created (I mean we cannot reference a
dynamically created control by FindControl(ctrlID) method.
Anyway, you can get still it by Request object.

Firstly you need assign ID to your TextBox like
Dim txtAircrafts As New TextBox
txtAircrafts.ID = "txtAircrafts"

Then using following code retrieve value in the text box
Dim str As String = Request.Form.Get("txtAircrafts")

Hope it's helpful to you.

Elton Wang

(e-mail address removed)
 
B

buran

Thank you Mr. Wang, this solved my problem :)


Elton Wang said:
It seems VS.2003 doesn't fully support controls
dynamically created (I mean we cannot reference a
dynamically created control by FindControl(ctrlID) method.
Anyway, you can get still it by Request object.

Firstly you need assign ID to your TextBox like
Dim txtAircrafts As New TextBox
txtAircrafts.ID = "txtAircrafts"

Then using following code retrieve value in the text box
Dim str As String = Request.Form.Get("txtAircrafts")

Hope it's helpful to you.

Elton Wang

(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top