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,