473,387 Members | 1,863 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,387 software developers and data experts.

Enable/disable all controls on a web page

I saw the C# solution:

for each Control c in Page.Controls
if c is WebControl --((WebControl)c).Enabled = False / true /
variable

But could figure out the VB syntax.

The closest I got was this:

Dim ctl As Control

For Each ctl In Page.Controls
if typeof(ctl) is TextBox then ((TextBox)c).Enabled =
False
Next

But I get a syntax error. Anybody know how to correct this?

If there is a more elegant solution, I'd surely like to know.

Thanks,

Aug 1 '06 #1
4 11166
<di****@earthlink.netwrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...
But I get a syntax error. Anybody know how to correct this?
Might be a bit easier if you actally say what the syntax error is...
Aug 1 '06 #2
For Each c As Control In Page.Controls
If TypeOf c Is TextBox Then
CType(c, TextBox).Enabled = True
End If
Next

My guess is that your casting was the syntax error, use ctype in vb.net

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
<di****@earthlink.netwrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...
>I saw the C# solution:

for each Control c in Page.Controls
if c is WebControl --((WebControl)c).Enabled = False / true /
variable

But could figure out the VB syntax.

The closest I got was this:

Dim ctl As Control

For Each ctl In Page.Controls
if typeof(ctl) is TextBox then ((TextBox)c).Enabled =
False
Next

But I get a syntax error. Anybody know how to correct this?

If there is a more elegant solution, I'd surely like to know.

Thanks,

Aug 1 '06 #3
I'm getting closer!

The syntax error description was just that "Syntax error".

"CType" did correct the error. Thanks Karl!

I implemented your code as you've written it. Except set enabled to
false.

My function now looks like this:

Private Sub DisableAllFields()

For Each c As Control In Page.Controls
If TypeOf (c) Is TextBox Then
CType(c, TextBox).Enabled = False
End If
Next

End Sub

No errors and compiles fine, but there are 20 controls on my page and
it only loops through 3 times.

Here are the values of 'c' as it loops through:

1. [System.Web.UI.ResourceBasedLiteralControl]
2. [System.Web.UI.HtmlControls.HtmlForm]
3. [System.Web.UI.LiteralControl]
Something tells me I'm not looping through the correct collection.
Either that or I am running this in my Page_Load sub and the controls
have not been instantiated yet. Any ideas?

Thanks,

Karl Seguin [MVP] wrote:
For Each c As Control In Page.Controls
If TypeOf c Is TextBox Then
CType(c, TextBox).Enabled = True
End If
Next

My guess is that your casting was the syntax error, use ctype in vb.net

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
<di****@earthlink.netwrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...
I saw the C# solution:

for each Control c in Page.Controls
if c is WebControl --((WebControl)c).Enabled = False / true /
variable

But could figure out the VB syntax.

The closest I got was this:

Dim ctl As Control

For Each ctl In Page.Controls
if typeof(ctl) is TextBox then ((TextBox)c).Enabled =
False
Next

But I get a syntax error. Anybody know how to correct this?

If there is a more elegant solution, I'd surely like to know.

Thanks,
Aug 1 '06 #4
I got it! Finally.

Page.Controls is a collection of three collections. I am interested in
the second collection, [System.Web.UI.HtmlControls.HtmlForm], which I
can reference like this Page.Controls(1).

Here's the final working version of my function:

Private Sub DisableAllFields()

For Each c As Control In Page.Controls(1).Controls

If TypeOf (c) Is TextBox Then
CType(c, TextBox).Enabled = False
End If

Next

End Sub

di****@earthlink.net wrote:
I'm getting closer!

The syntax error description was just that "Syntax error".

"CType" did correct the error. Thanks Karl!

I implemented your code as you've written it. Except set enabled to
false.

My function now looks like this:

Private Sub DisableAllFields()

For Each c As Control In Page.Controls
If TypeOf (c) Is TextBox Then
CType(c, TextBox).Enabled = False
End If
Next

End Sub

No errors and compiles fine, but there are 20 controls on my page and
it only loops through 3 times.

Here are the values of 'c' as it loops through:

1. [System.Web.UI.ResourceBasedLiteralControl]
2. [System.Web.UI.HtmlControls.HtmlForm]
3. [System.Web.UI.LiteralControl]
Something tells me I'm not looping through the correct collection.
Either that or I am running this in my Page_Load sub and the controls
have not been instantiated yet. Any ideas?

Thanks,

Karl Seguin [MVP] wrote:
For Each c As Control In Page.Controls
If TypeOf c Is TextBox Then
CType(c, TextBox).Enabled = True
End If
Next

My guess is that your casting was the syntax error, use ctype in vb.net

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
<di****@earthlink.netwrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...
>I saw the C# solution:
>
for each Control c in Page.Controls
if c is WebControl --((WebControl)c).Enabled = False / true /
variable
>
But could figure out the VB syntax.
>
The closest I got was this:
>
Dim ctl As Control
>
For Each ctl In Page.Controls
if typeof(ctl) is TextBox then ((TextBox)c).Enabled =
False
Next
>
But I get a syntax error. Anybody know how to correct this?
>
If there is a more elegant solution, I'd surely like to know.
>
Thanks,
>
Aug 1 '06 #5

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

Similar topics

1
by: Manatee | last post by:
Hi group. I have exactly one external, alternate stylesheet that I want to enable or disable by form controls, on one page only (not saved across pages). I used: <link rel="alternate...
3
by: DBQueen | last post by:
I have a form with lines of controls. On some of the lines there are 3 controls (call them A,B,C); other lines have only control A. The controls have been numbered sequentially (Q20, Q21....Q76)...
6
by: Stu Carter | last post by:
Hi, I have an aspx page where some controls are initially disabled by the code-behind 'Page_Load' event. I want these controls to be dynamically enabled when the user checks a checkbox. ...
2
by: buran | last post by:
Dear ASP.NET Programmers, I have a web user control (a search menu) which has 2 validation controls (one for input and another for the search criterion). I am including this search user control...
0
by: gabedog | last post by:
What would be a good (and safe) way to enable/disable a web site in a web farm that needs to come down for maintenance? Periodically, we have db folks that run db scripts. I'd like to put a back...
7
by: Phil | last post by:
on my form I have a checkbox and a tab control when the checkbox is true I wish to enable the controls on a single page of the tab control, is this possible or do I need to enable each control on...
3
by: swesorick | last post by:
I would like 95% of my site to have the viewstate disabled, in order to reduce the size of my pages. However, there are about 5% of the pages on my site that will require viewstate. Is there...
3
AccessIdiot
by: AccessIdiot | last post by:
I was successful with help from another thread (this one ) in enabling and disabling a form/subform with a button. Essentially you press a button on the form and the form controls are disabled but...
3
by: =?Utf-8?B?UGxhdGVyaW90?= | last post by:
I have link buttons in a Gridview that, depending on the value in another column (Not the Key column) will need to be disabled. For example, (Column2 has link buttons) Column1 ...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
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...

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.