473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

WebControls enumeration

Vik
Is there enumeration for the WebControls?

Thanks.
Nov 17 '05 #1
4 3646
try something like this

foreach (Control c in this.Controls)
{
if (c.GetType().ToString().Equals("System.Web.UI.WebC ontrols.TextBox")
{
// ...do something...
}
}

--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_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_author_plug>
----------------------------------------------

"Vik" <viktorum@==yahoo.com==> wrote in message
news:OQ**************@TK2MSFTNGP10.phx.gbl...
Is there enumeration for the WebControls?

Thanks.

Nov 17 '05 #2
If you're using VB try this:

For Each (Control c in Controls)
if TypeOf c is System.Web.UI.WebControl Then
// ...do something...
Next

-Mark
"John Timney (Microsoft MVP)" <xy********@btinternet.com> wrote in message
news:Oe**************@TK2MSFTNGP11.phx.gbl...
try something like this

foreach (Control c in this.Controls)
{
if (c.GetType().ToString().Equals("System.Web.UI.WebC ontrols.TextBox")
{
// ...do something...
}
}

--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_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_author_plug>
----------------------------------------------

"Vik" <viktorum@==yahoo.com==> wrote in message
news:OQ**************@TK2MSFTNGP10.phx.gbl...
Is there enumeration for the WebControls?

Thanks.


Nov 17 '05 #3
actually you need to recurse, or you will miss controls in usercontrols,
grids, etc.

walkControls(this.Controls);

void walkControls (Control c)
{
foreach (Control child in this.Controls)
{
walkControl(child);

if
(child.GetType().ToString().Equals("System.Web.UI. WebControls.TextBox")
{
// ...do something...
}
}
}
}

"John Timney (Microsoft MVP)" <xy********@btinternet.com> wrote in message
news:Oe**************@TK2MSFTNGP11.phx.gbl...
try something like this

foreach (Control c in this.Controls)
{
if (c.GetType().ToString().Equals("System.Web.UI.WebC ontrols.TextBox")
{
// ...do something...
}
}

--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_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_author_plug>
----------------------------------------------

"Vik" <viktorum@==yahoo.com==> wrote in message
news:OQ**************@TK2MSFTNGP10.phx.gbl...
Is there enumeration for the WebControls?

Thanks.


Nov 17 '05 #4
Vik
Thanks everybody.
Originally I had code like this which worked fine:

CtlType = ctl.GetType.Name
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="CompareValidator".

Vik

"Ben" <mu**********@120spamsaday.con> wrote in message
news:uH****************@TK2MSFTNGP10.phx.gbl...
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 "is", after all the code knows these types already and you verify that the code is correct at compile time. You need to itterate though the tree of controls
too as mentioned.

Ben W
"John Timney (Microsoft MVP)" <xy********@btinternet.com> wrote in message
news:Oe**************@TK2MSFTNGP11.phx.gbl...
try something like this

foreach (Control c in this.Controls)
{
if (c.GetType().ToString().Equals("System.Web.UI.WebC ontrols.TextBox") {
// ...do something...
}
}

--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_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_author_plug>
----------------------------------------------

"Vik" <viktorum@==yahoo.com==> wrote in message
news:OQ**************@TK2MSFTNGP10.phx.gbl...
Is there enumeration for the WebControls?

Thanks.



Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Justin Wright | last post by:
I know that I can set up an enumeration as follows ( just typed in quick so may have syntax errors ): <xsd:simpleType name="colors"> <xsd:restriction base="xsd:string"> <xsd:enumeration...
8
by: aevans1108 | last post by:
Greetings I can't seem to inherit enumerated values from a globally defined type in my XML schema. XmlSchema.Compile() doesn't like it. Here's the schema. <?xml version="1.0"...
2
by: Mark | last post by:
Assume you have an enumeration like PhoneType { Home, Business, Cell }. This enumeration corresponds with a lookup/dictionary table in your database like: phone_cd | phone_descr 1 ...
4
by: Marshal | last post by:
Sure... IEnumerable was inconvenient suggesting a separate class to service the enumeration, IEnumerator, and multiple operations: Current, MoveNext, Reset. (I'll warp the definition of "operation"...
1
by: Stefano G. | last post by:
I have a WSDL containing this enumeration type <xsd:simpleType name="item_type_enum"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="VCD"/> <xsd:enumeration value="SVCD"/>...
27
by: Ben Finney | last post by:
Antoon Pardon wrote: > I just downloaded your enum module for python > and played a bit with it. IMO some of the behaviour makes it less > usefull. Feedback is appreciated. I'm hoping to...
3
by: Davidoff | last post by:
Hi, I parse an XML file with a XSD schema. One XmlNode has an attribute whose type is a restriction of xs:string : <xs:simpleType name="stypeDay"> <xs:restriction base="xs:string">...
0
by: news.emn.fr | last post by:
Hello, i got this attribute <xs:attribute name="jour"> <xs:simpleType> <xs:restriction base="stypeJour"> </xs:restriction> </xs:simpleType> </xs:attribute>
3
by: eXt | last post by:
For a realtime-application (half an application at least, kind of a framework) I am working with I need a event managing system and naturally it must be fast. I have defined a set of available...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.