Problem with FindControl in VS 2003, VB.Net application

H

HannelieL

I have a table in HTML:

<table id="tblBudget" Runat="server">
<tr>
<TD width="1200px"></TD>
<TD width="1600px"></TD>
<TD width="500px"></TD>
<TD width="800px"></TD>
<TD width="500px"></TD>
</tr>
</table>


I populate the table in my code behind:

oTable = New System.Web.UI.HtmlControls.HtmlTable
oTable = Me.tblBudget
.....
oTableHeaderCell = New System.Web.UI.HtmlControls.HtmlTableCell
oComboBox = New DropDownList
oCodeset = New cls_CodeSet

'populate all institutions
oComboBox.DataSource = oCodeset.LoadCodesetWithCodeID(4)
oComboBox.ID = "ddNewUniv"
oComboBox.DataTextField = "Code"
oComboBox.DataValueField = "CodesetID"
oComboBox.DataBind()

oTableHeaderCell.ColSpan = 1 '2
oTableHeaderCell.Controls.Add(oComboBox)
oTableRow.Cells.Add(oTableHeaderCell)

.....add header row then add cells ... and add textbox to add values for
dropdown

'add input textboxes for new university entry
oTableCell = New System.Web.UI.HtmlControls.HtmlTableCell
oTextBox = New TextBox
oTextBox.ID = "NewUniv" & iPrevSubCat
oTextBox.Text = ""
oTextBox.Attributes.Add("onkeyup", "TestNumeric('" & oTextBox.ID &
"', '" & drRow("SubCatDesc") & "');")

' Add new control to a Table Cell in the row...
oTableCell.Controls.Add(oTextBox)
oTableRow.Cells.Add(oTableCell)

'add to Row and row to table
oTableRow.Cells.Add(oTableCell)
oTable.Rows.Add(oTableRow)
....

IN VIEW SOURCE: find dropdown :

<tr>
<td colspan="1" style="FONT-WEIGHT:Bold;">Category</td>
<td colspan="1">Sub Category</td>
<td colspan="1">Standard Rate</td>
<td colspan="1"><select name="ddNewUniv" id="ddNewUniv">
<option value="32">--Unknown--</option>
<option value="33">UCT</option>
<option value="34">UWC</option>
<option value="35">US</option>
<option value="36">NMMW</option>
<option value="37">UKZN</option>
<option value="38">WITS</option>
<option value="39">U-JHB</option>
<option value="40">NWU</option>
<option value="41">UFS</option>
<option value="42">UL</option>

</select></td>
<td colspan="1">TOTAL</td>
</tr>


and find textbox:

<td><input name="NewUniv1" type="text" id="NewUniv1"
onkeyup="TestNumeric('NewUniv1', 'Office Supplies / Services');" /></td>


......CANNOT FIND ANY OF THESE WITH FindControl when trying to save:


oComboBox = FindControl(sID) .....ALSO TRIED ' oComboBox =
FindControl("ddNewUniv")


AND

oTextBox = FindControl("NewUniv" & drRow("SubCatID"))
 
A

Arthur Dent

One thing to keep in mind is that FindControl is not recursive. It will only
find > direct < descendents of whichever control you call FindControl on.

I rolled my own (no guarantee that its at all optimized in any way) ... as
follows:

Public Function LocateControl(ByVal root As Control, ByVal id As String) As
Control
If root.ID = id Then Return root

For Each c As Control In root.Controls
Dim c2 As Control = LocateControl(c, id)
If Not c2 Is Nothing Then Return c2
Next

Return Nothing
End Function

HTH, Arthur.
 

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

Members online

Forum statistics

Threads
474,268
Messages
2,571,095
Members
48,773
Latest member
Kaybee

Latest Threads

Top