472,789 Members | 965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Programmatically manipulating all controls of type X?

I'm interested in programmatically manipulating groups of ASP.NET controls
by type. Can someone suggest code for the following?

Loop through, say, all label controls on a page, and assigning a CssClass to
them, or programmatically making the Visible/not Visible.

If applied to a containing page, such a function would traverse all user
controls statically and dynamically placed on the page, correct?

Thanks,
-KF
Dec 26 '06 #1
3 2578
Although you can loop recursively through all controls on the page starting
from this.Controls collection, check the type of every control and take
actions for required types, it doesn't seem to be an elegant solution. Why
don't you manipulate css rules instead? A css for span will cover all
labels. If you change it programmatically, all labels will change their
appearance.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Ken Fine" <ke*****@u.washington.eduwrote in message
news:em**********@gnus01.u.washington.edu...
I'm interested in programmatically manipulating groups of ASP.NET controls
by type. Can someone suggest code for the following?

Loop through, say, all label controls on a page, and assigning a CssClass
to them, or programmatically making the Visible/not Visible.

If applied to a containing page, such a function would traverse all user
controls statically and dynamically placed on the page, correct?

Thanks,
-KF

Dec 26 '06 #2
Thank you, Eliyahu, I thought about CSS as a solution for the specific case
I cited. My question more generally is about ways to programmatically
investigate the page, and I'd still like to know all of the ways I might
manage this.

I thought of another case that would be useful in addition to my earlier
query. So what I'd still like to know at this point is:

* how can I loop recursively through all controls on the page and manipulate
controls of type X
* how could I loop recursively through all controls on a page and manipulate
user controls with custom properties set to a specific value? What is the
last point in the page lifecycle that I would still be "permitted" to run
such a function (i.e. could some user control values be set
programmatically, and my looping function be run prior to the page being
rendered?)

-KF
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:%2****************@TK2MSFTNGP06.phx.gbl...
Although you can loop recursively through all controls on the page
starting from this.Controls collection, check the type of every control
and take actions for required types, it doesn't seem to be an elegant
solution. Why don't you manipulate css rules instead? A css for span will
cover all labels. If you change it programmatically, all labels will
change their appearance.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Ken Fine" <ke*****@u.washington.eduwrote in message
news:em**********@gnus01.u.washington.edu...
>I'm interested in programmatically manipulating groups of ASP.NET
controls by type. Can someone suggest code for the following?

Loop through, say, all label controls on a page, and assigning a CssClass
to them, or programmatically making the Visible/not Visible.

If applied to a containing page, such a function would traverse all user
controls statically and dynamically placed on the page, correct?

Thanks,
-KF


Dec 26 '06 #3
Something like this (I neither run nor compiled this code):

private void checkChildrenControls (Control control)
{
if (control.Controls != null)
foreach (Control childControl in control.Controls)
{
checkControl (childControl);
checkChildrenControls (childControl);
}
}

private void checkControl (Control control)
{
if (control is Label)
{
Label labelControl = Control as Label;
....
}
}

and somewhere in the Page methods:

this.checkChildrenControls (this);
..

You last point is the page's PreRender event.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Ken Fine" <ke*****@u.washington.eduwrote in message
news:em**********@gnus01.u.washington.edu...
Thank you, Eliyahu, I thought about CSS as a solution for the specific
case
I cited. My question more generally is about ways to programmatically
investigate the page, and I'd still like to know all of the ways I might
manage this.

I thought of another case that would be useful in addition to my earlier
query. So what I'd still like to know at this point is:

* how can I loop recursively through all controls on the page and
manipulate
controls of type X
* how could I loop recursively through all controls on a page and
manipulate
user controls with custom properties set to a specific value? What is the
last point in the page lifecycle that I would still be "permitted" to run
such a function (i.e. could some user control values be set
programmatically, and my looping function be run prior to the page being
rendered?)

-KF
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:%2****************@TK2MSFTNGP06.phx.gbl...
Although you can loop recursively through all controls on the page
starting from this.Controls collection, check the type of every control
and take actions for required types, it doesn't seem to be an elegant
solution. Why don't you manipulate css rules instead? A css for span
will
cover all labels. If you change it programmatically, all labels will
change their appearance.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Ken Fine" <ke*****@u.washington.eduwrote in message
news:em**********@gnus01.u.washington.edu...
I'm interested in programmatically manipulating groups of ASP.NET
controls by type. Can someone suggest code for the following?

Loop through, say, all label controls on a page, and assigning a
CssClass
to them, or programmatically making the Visible/not Visible.

If applied to a containing page, such a function would traverse all
user
controls statically and dynamically placed on the page, correct?

Thanks,
-KF


Dec 26 '06 #4

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

Similar topics

8
by: deko | last post by:
I'm trying to find a way to set form/control properties programmatically. In a nut shell: 1. Open a database 2. Open a form in design view 3. Do something like this: For Each prp In...
1
by: Martine | last post by:
Hi there! I have a problem with programmatically adding user controls to my mobile webforms. If I load my usercontrol programmatically (in the Page_Load), the object is instantiated, I have...
2
by: Nicole | last post by:
I am creating template columns programmatically. I have read the msdn article on this and I'm so close. Article:...
9
by: Rob Meade | last post by:
Hi all, I have a form which is programmatically created from reading values from a database table. There is a 'form' for each DocumentType - when I say form I mean as in a different form will...
18
by: Julia Hu | last post by:
Hi, I have a datagrid, and in different rows I need to programmatically bind different type of controls and load data into these controls. For example,in the first row I need to bind data into a...
5
by: Neal | last post by:
Hi I need to change my mousepointer when the mouse moves over certain populated controls on my aspx page. I've tried the following but without success (after visiting a site recommended from...
4
by: BentleyInc | last post by:
I'm trying to find a way to add a whildcard application mapping to aspnet_isapi.dll in IIS programmatically.... been looking into IIS administrator reference but didn't find the right function to...
5
by: masterej | last post by:
Developers, Is there any way to disable all checkboxes on a form? I have a form with 160 checkboxes and I want to be able to disable all of them. Is there a way I can do something like this: ...
3
by: John | last post by:
Hi I am trying to manipulation asp.net membership programmatically from a winform app. I have added the connectionstring and membership & role setting fragment to my app's app.config file as per...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.