473,546 Members | 2,249 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Processing all controls on a page

Hi,

I want to process all controls on a page, to check for a specific attribute
(a specific custom attribute I added).

I try with the following code
Dim oCtrl As WebControls.Web Control

For Each oCtrl In Page.Controls

If oCtrl.Attribute s("bzDisable" ) = "1" Then

oCtrl.Enabled = false

End If

Next

bzDisable is a custom attribute I added to Textbox control in .ASPX page

and it gives me this error:
Exception Details: System.InvalidC astException: Specified cast is not valid.

Can anyone tell me what I did wrong?

Thank you.
Bogdan
Nov 17 '05 #1
4 1948
"Bogdan Zamfir" <ams_soft at pcnet dot ro> wrote in message
news:ur******** ******@tk2msftn gp13.phx.gbl...
Hi,

I want to process all controls on a page, to check for a specific attribute (a specific custom attribute I added).

I try with the following code
Dim oCtrl As WebControls.Web Control

For Each oCtrl In Page.Controls

If oCtrl.Attribute s("bzDisable" ) = "1" Then

oCtrl.Enabled = false

End If

Next


Page.Controls is a collection of Control objects, not of WebControl objects.

--
John Saunders
Internet Engineer
jo***********@s urfcontrol.com
Nov 17 '05 #2
Okay, first of all, starting at Page level is going to return a bunch of
LiteralControls with the HTML for the page in them, and your WebForm, which
is NOT the Page, but the form in the Page. If you want to get all the
Controls on the Form, use:

Dim objControl As Control
For Each objControl in Page.FindContro l("Form1").Cont rols

Then you need to ascertain that the Control is a WebControl. If the Form has
any HTML in it, it will also be converted to LiteralControls . However, if
you start with a type of Control, you can use Reflection if necessary, and
cast it to whatever type you need to look at.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Neither a follower nor a lender be.

"Bogdan Zamfir" <ams_soft at pcnet dot ro> wrote in message
news:ur******** ******@tk2msftn gp13.phx.gbl...
Hi,

I want to process all controls on a page, to check for a specific attribute (a specific custom attribute I added).

I try with the following code
Dim oCtrl As WebControls.Web Control

For Each oCtrl In Page.Controls

If oCtrl.Attribute s("bzDisable" ) = "1" Then

oCtrl.Enabled = false

End If

Next

bzDisable is a custom attribute I added to Textbox control in .ASPX page

and it gives me this error:
Exception Details: System.InvalidC astException: Specified cast is not valid.
Can anyone tell me what I did wrong?

Thank you.
Bogdan

Nov 17 '05 #3
Hi

See below

"Kevin Spencer" <ke***@takempis .com> wrote in message
news:ee******** *******@TK2MSFT NGP09.phx.gbl.. .
Okay, first of all, starting at Page level is going to return a bunch of
LiteralControls with the HTML for the page in them, and your WebForm, which is NOT the Page, but the form in the Page. If you want to get all the
Controls on the Form, use:

Dim objControl As Control
For Each objControl in Page.FindContro l("Form1").Cont rols

Then you need to ascertain that the Control is a WebControl. If the Form has any HTML in it, it will also be converted to LiteralControls . However, if
you start with a type of Control, you can use Reflection if necessary, and
cast it to whatever type you need to look at.
1. What is Reflection and what is it used for?
2. What is LiteralControls and how does that differentiate from our normal
web controls?

Cheers

J

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
http://www.takempis.com
Neither a follower nor a lender be.

"Bogdan Zamfir" <ams_soft at pcnet dot ro> wrote in message
news:ur******** ******@tk2msftn gp13.phx.gbl...
Hi,

I want to process all controls on a page, to check for a specific

attribute
(a specific custom attribute I added).

I try with the following code
Dim oCtrl As WebControls.Web Control

For Each oCtrl In Page.Controls

If oCtrl.Attribute s("bzDisable" ) = "1" Then

oCtrl.Enabled = false

End If

Next

bzDisable is a custom attribute I added to Textbox control in .ASPX page

and it gives me this error:
Exception Details: System.InvalidC astException: Specified cast is not

valid.

Can anyone tell me what I did wrong?

Thank you.
Bogdan


Nov 17 '05 #4
Hi James,
1. What is Reflection and what is it used for?
The System.Reflecti on namespace is a set of classes that are used to
discover information about .Net classes and assemblies. You can find out
anything you want to about any class or assembly using these classes.
2. What is LiteralControls and how does that differentiate from our normal
web controls?
A LiteralControl is a Control which contains only Text. It can contain HTML
or any other type of plain text. When a Page is parsed, all HTML in the Page
that is not part of a Control is converted to LiteralControls .

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Neither a follower nor a lender be.

"James Zhuo" <na************ **@optusnet.com .au> wrote in message
news:Oa******** ******@TK2MSFTN GP12.phx.gbl... Hi

See below

"Kevin Spencer" <ke***@takempis .com> wrote in message
news:ee******** *******@TK2MSFT NGP09.phx.gbl.. .
Okay, first of all, starting at Page level is going to return a bunch of
LiteralControls with the HTML for the page in them, and your WebForm,

which
is NOT the Page, but the form in the Page. If you want to get all the
Controls on the Form, use:

Dim objControl As Control
For Each objControl in Page.FindContro l("Form1").Cont rols

Then you need to ascertain that the Control is a WebControl. If the Form

has
any HTML in it, it will also be converted to LiteralControls . However, if you start with a type of Control, you can use Reflection if necessary, and cast it to whatever type you need to look at.


1. What is Reflection and what is it used for?
2. What is LiteralControls and how does that differentiate from our normal
web controls?

Cheers

J

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
http://www.takempis.com
Neither a follower nor a lender be.

"Bogdan Zamfir" <ams_soft at pcnet dot ro> wrote in message
news:ur******** ******@tk2msftn gp13.phx.gbl...
Hi,

I want to process all controls on a page, to check for a specific

attribute
(a specific custom attribute I added).

I try with the following code
Dim oCtrl As WebControls.Web Control

For Each oCtrl In Page.Controls

If oCtrl.Attribute s("bzDisable" ) = "1" Then

oCtrl.Enabled = false

End If

Next

bzDisable is a custom attribute I added to Textbox control in .ASPX page
and it gives me this error:
Exception Details: System.InvalidC astException: Specified cast is not

valid.

Can anyone tell me what I did wrong?

Thank you.
Bogdan



Nov 17 '05 #5

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

Similar topics

4
1549
by: Bogdan Zamfir | last post by:
Hi, I want to enable / disable several controls on a page based on a condition in application. But there are several other controls on the page don't want to enable / disable together with the others. In desktop applications, I used a control's property who was not used, like Comment or Tag.
11
1750
by: Glen Wolinsky | last post by:
This is my first attempt as asynchronous processing. I have created a small test app as proof of concept, but I am having one proglem. In the example (code listed below), my callback routine has two problems: 1. It runs TWICE; and 2. While it seems to update the web page controls, the results never show up on the page. I am using...
2
2544
by: Dave Williamson | last post by:
When a ASPX page is created with dynamic controls based on what the user is doing the programmer must recreate the dynamic controls again on PostBack in the Page_Load so that it's events are wired and are called like a static control. Here is the problem that I need to solve. The processing overhead that occurs to determine what dynamic...
5
1487
by: Joe Reazor | last post by:
I've got an asp.net page that has approximately 1,440 controls on it. You must think I'm crazy, but we need to have the page organized in this fashion. As you can imagine, the page takes a very long to to process, on the order of 20-30 seconds, even though only a small number of the controls are generally visible at once it still has to...
1
3089
by: Jim in Arizona | last post by:
I'm having dificulty figuring out how to process multiple check boxes on a web form. Let's say I have three check boxes: cbox1 cbox2 cbox3 The only way I can think of to code the possibilities is something like:
6
4967
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing for long running reports. When the processing is complete it uses crystal reports to load a template file, populate it, and then export it to a...
1
1012
by: tony | last post by:
....can anyone direct me towards a form processor. i am switching from basic ASP to .NET and am a little confused on how the form data is processed. I plan on the data being sent via email, and to MySQL dbase. thanks all....
1
1119
by: SyracuseCheer | last post by:
I have a VS.NET 2003 project that's giving me issues. Any assistance would be greatly appreciated! I have a fairly straight-forward system of server controls and web services, where the server controls access the web services for content. The prolem I'm having is very odd. One of my controls is calling the corresponding web service as...
6
1413
by: DC | last post by:
Hi, our cms (asp.net 2.0) dynamically inserts controls into asp.net pages, sometimes 50 and more per page, and if we run into a performance bottleneck we have a hard time finding out which controls cause latencies. We can find most of these bottlenecks by monitoring db traffic with profiler, but we are now using an increasing amount of...
0
7504
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7694
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6026
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5360
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3491
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.