HighTechTalks DotNet Forums  

Problem with FindControl in VS 2003, VB.Net application

ASP.net Building Controls microsoft.public.dotnet.framework.aspnet.buildingcontrols


Discuss Problem with FindControl in VS 2003, VB.Net application in the ASP.net Building Controls forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
HannelieL
 
Posts: n/a

Default Problem with FindControl in VS 2003, VB.Net application - 07-11-2006 , 11:57 AM






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


Reply With Quote
  #2  
Old   
Arthur Dent
 
Posts: n/a

Default Re: Problem with FindControl in VS 2003, VB.Net application - 08-15-2006 , 04:21 PM






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.



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.