foreach (Control c in this.Controls)
{
if (c.GetType().To String().Equals ("System.Web.UI .WebControls.Te xtBox")
{
// ...do something...
}
}
--
Regards
John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_auth or_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_autho r_plug>
----------------------------------------------
"Vik" <viktorum@==yah oo.com==> wrote in message
news:OQriV2kRDH A.1720@TK2MSFTN GP10.phx.gbl...[color=blue]
> Is there enumeration for the WebControls?
>
> Thanks.
>
>[/color]
Thanks everybody.
Originally I had code like this which worked fine:
CtlType = ctl.GetType.Nam e
Select Case CtlType
Case "TextBox"
....
Case "Label"
....
End Select
I changed it to:
If TypeOf ctl Is TextBox Then
....
ElseIf TypeOf ctl Is Label Then
....
End If
This code does not work because TypeOf ctl Is Label = True for example when
CtlType="Compar eValidator".
Vik
"Ben" <mustbejoking@1 20spamsaday.con > wrote in message
news:uHe%23xAnR DHA.2676@TK2MSF TNGP10.phx.gbl. ..[color=blue]
> ToString.Equals () or == is not very type safe, great for displaying to a
> console or output file but in code you should really use "typeof" and[/color]
"is",[color=blue]
> after all the code knows these types already and you verify that the code[/color]
is[color=blue]
> correct at compile time. You need to itterate though the tree of controls
> too as mentioned.
>
> Ben W
>
>
> "John Timney (Microsoft MVP)" <xyztimneyj@bti nternet.com> wrote in message
> news:OeDr3LlRDH A.1804@TK2MSFTN GP11.phx.gbl...[color=green]
> > try something like this
> >
> > foreach (Control c in this.Controls)
> > {
> > if[/color][/color]
(c.GetType().To String().Equals ("System.Web.UI .WebControls.Te xtBox")[color=blue][color=green]
> > {
> > // ...do something...
> > }
> > }
> >
> >
> >
> > --
> > Regards
> >
> > John Timney (Microsoft ASP.NET MVP)
> > ----------------------------------------------
> > <shameless_auth or_plug>
> > Professional .NET for Java Developers with C#
> > ISBN:1-861007-91-4
> > Professional Windows Forms
> > ISBN: 1861005547
> > Professional JSP 2nd Edition
> > ISBN: 1861004958
> > Professional JSP
> > ISBN: 1861003625
> > Beginning JSP Web Development
> > ISBN: 1861002092
> > </shameless_autho r_plug>
> > ----------------------------------------------
> >
> > "Vik" <viktorum@==yah oo.com==> wrote in message
> > news:OQriV2kRDH A.1720@TK2MSFTN GP10.phx.gbl...[color=darkred]
> > > Is there enumeration for the WebControls?
> > >
> > > Thanks.
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]
Comment