472,125 Members | 1,381 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

enable a control programatically vb.net (asp)

Hope someone could help.

I read all the controls on a page using the following statement:

For i = 0 To Page.Form.Controls.Count - 1
try
Page.Form.Controls.Item(i).Visible = False
' here I would not like to set the property to "visible" to false.
'I would rather set the enable property to false
Catch
End Try
Next

The controls are checked against a security table whether the user should have access to it or not. If not access, the enable property must be set to false.
On entering the dot - no "enable" property is shown and I dont know how to get to work. I use visio studio 2005

Please help!
Regards
Francois
Oct 26 '06 #1
1 2655
Hai

i'm a rookie in programming. when i came accross a similar problem i searched the net then i got this posting

i tried my self and got a solution
this function below solvet the problem


Private Function EnableCntrls(ByVal Switch As Boolean) As Boolean
Dim i As Integer
If Switch = False Then
For i = 0 To frmDefault.Controls.Count - 1
Dim Str As String
Str = frmDefault.Controls.Item(i).GetType().ToString
If Str = "System.Web.UI.WebControls.TextBox" Then
Dim cntrl As WebControl
cntrl = frmDefault.FindControl(frmDefault.Controls.Item(i) .ID)
cntrl.Enabled = False
End If
If Str = "System.Web.UI.WebControls.DropDownList" Then
Dim cntrl As WebControl
cntrl = frmDefault.FindControl(frmDefault.Controls.Item(i) .ID)
cntrl.Enabled = False
End If
Next
Else
For i = 0 To frmDefault.Controls.Count - 1
Dim Str As String
Str = frmDefault.Controls.Item(i).GetType().ToString
If Str = "System.Web.UI.WebControls.TextBox" Then
Dim cntrl As WebControl
cntrl = frmDefault.FindControl(frmDefault.Controls.Item(i) .ID)
cntrl.Enabled = True
End If
If Str = "System.Web.UI.WebControls.DropDownList" Then
Dim cntrl As WebControl
cntrl = frmDefault.FindControl(frmDefault.Controls.Item(i) .ID)
cntrl.Enabled = True
End If
Next
End If
End Function
Jan 6 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by martin | last post: by
1 post views Thread by francois | last post: by
2 posts views Thread by francois | last post: by
2 posts views Thread by Edgardo Rossetto | last post: by
2 posts views Thread by rn5a | last post: by
1 post views Thread by =?Utf-8?B?Tmlrb2xheSBQb2Rrb2x6aW4=?= | last post: by
reply views Thread by leo001 | last post: by

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.