Subscribe to There and Back again, a Coders Blog        RSS Feed
-----

FindControl generic methods

Icon Leave Comment
After months of grinding the knowledge and concievable possibilities (which aint too much on my part :) ), I have developed a series of methods, that i am using on a project atm, that allows me to access a property for a WebControl, Control, or specific property for a control through Generics Hierarchy.

Below i will list the core and the supports then the specifics. Regardless of what type it is, they all use the ControlRef core method to get a control instance before access its specific properties or methods.

You can find the snippet at FindControl
Friend Function ControlRef(Of T As Control)(ByVal parent As Control, ByVal cntrlName As String) As T
  Return CType(parent.FindControl(cntrlName), T)
End Function



Some example uses of a higher level generic:
Friend Function GetVisible(Of T As Control)(ByVal parent As Control, ByVal cntrlName As String) As Boolean
  Return ControlRef(Of T)(parent, cntrlName).Visible
End Function
Friend Sub SetVisible(Of T As Control)(ByVal parent As Control, ByVal cntrlName As String, ByVal value As Boolean)
  ControlRef(Of T)(parent, cntrlName).Visible = value
End Sub



An even higher level generic:
Friend Function GetSelected(Of T As DropDownList)(ByVal parent As Control, ByVal cntrlname As String) As ListItem
  Return ControlRef(Of T)(parent, cntrlname).SelectedItem
End Function



Edited (2/26/2010):
Found out that this Snippet i posted above had been deleted, with no response, so here it is in its form and usage.
snippet address was: Here

0 Comments On This Entry

 

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

0 user(s) viewing

0 Guests
0 member(s)
0 anonymous member(s)

Search My Blog

July 2014

S M T W T F S
  12345
6789101112
13141516171819
202122232425 26
2728293031  

Recent Entries