Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > FindControl by type?

Reply
Thread Tools

FindControl by type?

 
 
TR
Guest
Posts: n/a
 
      05-25-2005
I have an aspanel 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


 
Reply With Quote
 
 
 
 
Axel Dahmen
Guest
Posts: n/a
 
      05-25-2005
Dim Crtl as System.Web.UI.Control
For Each Ctrl in MyPanel.Controls
If TypeOf Ctrl Is CheckBox Then


HTH,
Axel Dahmen


 
Reply With Quote
 
 
 
 
TR
Guest
Posts: n/a
 
      05-25-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Dim Crtl as System.Web.UI.Control
> For Each Ctrl in MyPanel.Controls
> If TypeOf Ctrl Is CheckBox Then
>
>
> HTH,
> Axel Dahmen
>
>



 
Reply With Quote
 
Axel Dahmen
Guest
Posts: n/a
 
      05-26-2005
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" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Dim Crtl as System.Web.UI.Control
> > For Each Ctrl in MyPanel.Controls
> > If TypeOf Ctrl Is CheckBox Then
> >
> >
> > HTH,
> > Axel Dahmen
> >
> >

>
>



 
Reply With Quote
 
Timo
Guest
Posts: n/a
 
      05-27-2005
Danke sehr, Axel.


"Axel Dahmen" <(E-Mail Removed)> wrote in message
news:OZK#(E-Mail Removed)...
> 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" <(E-Mail Removed)> schrieb im Newsbeitrag
> news:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Dim Crtl as System.Web.UI.Control
> > > For Each Ctrl in MyPanel.Controls
> > > If TypeOf Ctrl Is CheckBox Then
> > >
> > >
> > > HTH,
> > > Axel Dahmen
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FindControl method doesn't work ani ASP .Net 0 11-05-2003 03:47 PM
Assigned ID gets changed! (FindControl not working) Ivan Demkovitch ASP .Net 1 10-07-2003 08:16 PM
FindControl() returns NULL when object exists in Template? James G. Beldock ASP .Net 1 08-07-2003 09:19 PM
FindControl Ravikanth[MVP] ASP .Net 2 07-22-2003 08:16 AM
OnEditCommand - .FindControl Returning Null George Durzi ASP .Net 0 07-14-2003 09:54 PM



Advertisments