I'm trying to simply get the value of a FormView control IDLabel1 that is placed within a div
IDLabel1 is a bound control getting data from a database via an sqldatasource control
I've tried the following:
FormView1.FindControl("IDLabel1")
CType(FormView1.FindControl("IDLabel1"),Label)
Dim lbl As Label = DirectCast(FindControl("IDLabel1"), Label)
Dim lbl As Label = DirectCast(FindControl("FormView1&IDLabel1"), Label)
Dim lbl As Label = DirectCast(Page.FindControl("FormView1").FindControl(IDLabel1), Label)
All the above returns error control has null value. I've also tried the following Function:
Public Shared Function FindCont(controlId As String, controls As ControlCollection) As Control
For Each control As Control In controls
If control.ID = controlId Then
Return control
End If
If control.HasControls() Then
Dim nestedControl As Control = FindCont(controlId, control.Controls)
If nestedControl IsNot Nothing Then
Return nestedControl
End If
End If
Next
Return Nothing
End Function
I've also tried data binding before calling FindControl
Again using this function I only get a null return.
The only thing I can think of now is that the problem might have something to do with the div??
Any help will be appreciated