just found this function from a blog post by Steele Price and it worked perfectly. I was trying to reference a usercontrol inside a page that had a master page, nothing I tried worked except this. Put it in one of your core classes. Read Steele's blog post for more details.
If you put this in a class you will need to get the control reference like:
Dim imgStep2PreviewIcon As Image = Eyespike.Utilities.FindControl(Of Control)(Page, "imgStep1PreviewIcon")
imgStep2PreviewIcon.Visible = False
VB.NET Code
Public Shadows Function FindControl(ByVal id As String) As Control
Return FindControl(Of Control)(Page, id)
End Function
Public Shared Shadows Function FindControl(Of T As Control)(ByVal startingControl As Control, ByVal id As String) As T
Dim found As Control = startingControl
If (String.IsNullOrEmpty(id) OrElse (found Is Nothing)) Then Return CType(Nothing, T)
If String.Compare(id, found.ID) = 0 Then Return found
For Each ctl As Control In startingControl.Controls
found = FindControl(Of Control)(ctl, id)
If (found IsNot Nothing) Then Return found
Next
Return CType(Nothing, T)
End Function
C# (untested, generated using converter.telerik.com)
public new Control FindControl(string id)
{
return FindControl<Control>(Page, id);
}
public static new T FindControl<T>(Control startingControl, string id) where T : Control
{
Control found = startingControl;
if ((string.IsNullOrEmpty(id) || (found == null))) return (T)null;
if (string.Compare(id, found.ID) == 0) return found;
foreach (Control ctl in startingControl.Controls) {
found = FindControl<Control>(ctl, id);
if ((found != null)) return found;
}
return (T)null;
}