Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>just found this function from a <a href="http://blog.steeleprice.net/archive/2007/04/23/1142.aspx" rel="nofollow noreferrer">blog post</a> 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 <a href="http://blog.steeleprice.net/archive/2007/04/23/1142.aspx" rel="nofollow noreferrer">Steele's blog post</a> for more details.</p> <p>If you put this in a class you will need to get the control reference like:</p> <pre><code>Dim imgStep2PreviewIcon As Image = Eyespike.Utilities.FindControl(Of Control)(Page, "imgStep1PreviewIcon") imgStep2PreviewIcon.Visible = False </code></pre> <p><strong>VB.NET Code</strong></p> <pre><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 </code></pre> <p><strong>C#</strong> (untested, generated using <a href="http://converter.telerik.com" rel="nofollow noreferrer">converter.telerik.com</a>)</p> <pre><code>public new Control FindControl(string id) { return FindControl&lt;Control&gt;(Page, id); } public static new T FindControl&lt;T&gt;(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&lt;Control&gt;(ctl, id); if ((found != null)) return found; } return (T)null; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload