FindControl by type?

Discussion in 'ASP .Net' started by TR, May 25, 2005.

  1. TR

    TR Guest

    I have an asp:panel that contains a variety of controls, including
    checkboxes and HtmlGenericControls. I can find the panel in codebehind using
    FindControl(id), but then I want to either:

    a) iterate all of the controls in the panel's Controls collection and, if
    the control is a checkbox ..., or
    b) find only the checkboxes in the panel and iterate through them

    Using approach a) how do I determine if the current control is a checkbox?

    Dim Crtl as System.Web.UI.Control
    For Each Ctrl in MyPanel.Controls
    If Ctrl ....


    Is b) possible server-side? Is there a Find By Control Type?

    Thanks for the help.
    TR
     
    TR, May 25, 2005
    #1
    1. Advertising

  2. TR

    Axel Dahmen Guest

    Dim Crtl as System.Web.UI.Control
    For Each Ctrl in MyPanel.Controls
    If TypeOf Ctrl Is CheckBox Then


    HTH,
    Axel Dahmen
     
    Axel Dahmen, May 25, 2005
    #2
    1. Advertising

  3. TR

    TR Guest

    Re: FindControl by type? followup question

    Thanks, Axel. Perhaps you could help with another related question? If I
    wanted to create a *generic* class to look for all instances of a specified
    type of control in a given container, how would I specify the type? Given
    the following signature, how would the blank be filled in, in the If
    TypeOf... line? Is there a function that takes a string name for a type and
    returns an object that makes sense to TypeOf ...?

    Public Sub FindType(ByVal MyContainer as System.Web.UI.Control, ByVal mytype
    as String)
    Dim Ctrl as System.Web.UI.Control
    For Each Ctrl in MyContainer.Controls
    If TypeOf Ctrl is ___________ Then
    ...
    End If
    Next
    End Sub

    Thanks again.
    TR




    "Axel Dahmen" <> wrote in message
    news:...
    > Dim Crtl as System.Web.UI.Control
    > For Each Ctrl in MyPanel.Controls
    > If TypeOf Ctrl Is CheckBox Then
    >
    >
    > HTH,
    > Axel Dahmen
    >
    >
     
    TR, May 25, 2005
    #3
  4. TR

    Axel Dahmen Guest

    Re: FindControl by type? followup question

    Hi, TR,

    Schau mal unter "Type-Klasse" bzw. "Type class" in der MSDN-Hilfe. Mit der
    Type-Klasse, z.B.:

    Dim t As Type = GetType(Array)
    If t.FullName = ....

    oder

    If t.GUID = ...

    HTH,
    Axel

    ------------
    "TR" <> schrieb im Newsbeitrag
    news:...
    > Thanks, Axel. Perhaps you could help with another related question? If I
    > wanted to create a *generic* class to look for all instances of a

    specified
    > type of control in a given container, how would I specify the type? Given
    > the following signature, how would the blank be filled in, in the If
    > TypeOf... line? Is there a function that takes a string name for a type

    and
    > returns an object that makes sense to TypeOf ...?
    >
    > Public Sub FindType(ByVal MyContainer as System.Web.UI.Control, ByVal

    mytype
    > as String)
    > Dim Ctrl as System.Web.UI.Control
    > For Each Ctrl in MyContainer.Controls
    > If TypeOf Ctrl is ___________ Then
    > ...
    > End If
    > Next
    > End Sub
    >
    > Thanks again.
    > TR
    >
    >
    >
    >
    > "Axel Dahmen" <> wrote in message
    > news:...
    > > Dim Crtl as System.Web.UI.Control
    > > For Each Ctrl in MyPanel.Controls
    > > If TypeOf Ctrl Is CheckBox Then
    > >
    > >
    > > HTH,
    > > Axel Dahmen
    > >
    > >

    >
    >
     
    Axel Dahmen, May 27, 2005
    #4
  5. TR

    Timo Guest

    Re: FindControl by type? followup question

    Danke sehr, Axel.


    "Axel Dahmen" <> wrote in message
    news:OZK#...
    > Hi, TR,
    >
    > Schau mal unter "Type-Klasse" bzw. "Type class" in der MSDN-Hilfe. Mit der
    > Type-Klasse, z.B.:
    >
    > Dim t As Type = GetType(Array)
    > If t.FullName = ....
    >
    > oder
    >
    > If t.GUID = ...
    >
    > HTH,
    > Axel
    >
    > ------------
    > "TR" <> schrieb im Newsbeitrag
    > news:...
    > > Thanks, Axel. Perhaps you could help with another related question? If I
    > > wanted to create a *generic* class to look for all instances of a

    > specified
    > > type of control in a given container, how would I specify the type?

    Given
    > > the following signature, how would the blank be filled in, in the If
    > > TypeOf... line? Is there a function that takes a string name for a type

    > and
    > > returns an object that makes sense to TypeOf ...?
    > >
    > > Public Sub FindType(ByVal MyContainer as System.Web.UI.Control, ByVal

    > mytype
    > > as String)
    > > Dim Ctrl as System.Web.UI.Control
    > > For Each Ctrl in MyContainer.Controls
    > > If TypeOf Ctrl is ___________ Then
    > > ...
    > > End If
    > > Next
    > > End Sub
    > >
    > > Thanks again.
    > > TR
    > >
    > >
    > >
    > >
    > > "Axel Dahmen" <> wrote in message
    > > news:...
    > > > Dim Crtl as System.Web.UI.Control
    > > > For Each Ctrl in MyPanel.Controls
    > > > If TypeOf Ctrl Is CheckBox Then
    > > >
    > > >
    > > > HTH,
    > > > Axel Dahmen
    > > >
    > > >

    > >
    > >

    >
    >
     
    Timo, May 27, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin Eyles

    Page.FindControl type casting

    Martin Eyles, Sep 15, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    3,587
    Martin Eyles
    Sep 15, 2005
  2. jobs
    Replies:
    0
    Views:
    424
  3. Replies:
    5
    Views:
    417
    dcherna
    Jan 17, 2007
  4. Replies:
    2
    Views:
    1,996
  5. TR

    FindControl by type?

    TR, May 25, 2005, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    692
Loading...

Share This Page