473,407 Members | 2,676 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,407 software developers and data experts.

Setup visibility of controls programmatically

Hello!

I am working on an on-line ASP.Net library.
I would like to set up the visibility of some controls programmatically.
My approach is to give an "admin_" prefix to some controls and to define
their visibility by the procedure below ....

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
.....
Call SetUpVisibility_AdminControls(False)
....
End sub
....
....
Sub SetUpVisibility_AdminControls(ByVal Adminlevel As Boolean)
Dim obj_Control As Control
For Each obj_Control In Page.Controls
If Left(obj_Control.ID, 6) = "admin_" Then
Page.FindControl(obj_Control.ID)
obj_Control.Visible = Adminlevel
End If
Next
End Sub

For reason (...), this just does not work and, whatever the value of the
boolean "AdminLevel", the controls are always visible.

Thanks in advance for your support.

Michel

Nov 18 '05 #1
2 1398
Michel,

Are you sure that the controls have Page as their direct parent , if
your control is in some placeholder like Table, usercontrol, your code
won't fulfill your requirement.

your can do recursive search. Hope it's the key. If not, hope you can
solve it with others' help.

Good luck!

Edward

Hello!

I am working on an on-line ASP.Net library.
I would like to set up the visibility of some controls programmatically.
My approach is to give an "admin_" prefix to some controls and to define
their visibility by the procedure below ....

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
....
Call SetUpVisibility_AdminControls(False)
...
End sub
...
...
Sub SetUpVisibility_AdminControls(ByVal Adminlevel As Boolean)
Dim obj_Control As Control
For Each obj_Control In Page.Controls
If Left(obj_Control.ID, 6) = "admin_" Then
Page.FindControl(obj_Control.ID)
obj_Control.Visible = Adminlevel
End If
Next
End Sub

For reason (...), this just does not work and, whatever the value of the
boolean "AdminLevel", the controls are always visible.

Thanks in advance for your support.

Michel

Nov 18 '05 #2

"Michel Couche" <Mi*******************@euronet.be> wrote in message news:Oq**************@TK2MSFTNGP12.phx.gbl...
Hello!

I am working on an on-line ASP.Net library.
I would like to set up the visibility of some controls programmatically.
My approach is to give an "admin_" prefix to some controls and to define
their visibility by the procedure below ....

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
....
Call SetUpVisibility_AdminControls(False)
...
End sub
...
...
Sub SetUpVisibility_AdminControls(ByVal Adminlevel As Boolean)
Dim obj_Control As Control
For Each obj_Control In Page.Controls
If Left(obj_Control.ID, 6) = "admin_" Then
Page.FindControl(obj_Control.ID)
obj_Control.Visible = Adminlevel
End If
Next
End Sub

For reason (...), this just does not work and, whatever the value of the
boolean "AdminLevel", the controls are always visible.

Thanks in advance for your support.

Michel


You don't need that "Page.FindControl" in there, you already *have*
a control. Plus this is a function and you ignore any result!
As Edward replied, you need to do a recursive search.

Hans Kesting
Nov 18 '05 #3

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

Similar topics

2
by: MENTAT | last post by:
Hi, I am trying to create an installer for my web application. So I added a web setup project to my solution (I am using VS.NET 2003). Been playing around with it since then and it basically...
1
by: Micky Pearce | last post by:
Hi I have a page containing a hidden <div> called 'controls' plus an <iframe> containing a second page. I need to be able to set the visibility of the 'controls' div when the page in the iframe...
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
6
by: Nick Stansbury | last post by:
Hi, I have a loop running on Page_PreRender that sets a number of controls to invisible based on a set of criteria. Before I do this however, I set all of the drop down lists to be visible with...
11
by: -D- | last post by:
How can I turn the visibility of the xml control on or off? <%@ Control Language="c#" AutoEventWireup="false" Codebehind="TopNavBar.ascx.cs" Inherits="compass.user_controls.TopNavBar"...
0
by: Michel Couche | last post by:
Hello, I would like to programmatically set the visibility of a selectedWizardStep after clicking on a button contained in an other one. I found the following in an article from D. Esposito...
3
by: Ken Fine | last post by:
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...
2
by: Jamey Bon | last post by:
I am a C# newbie. I am having a tough time with several issues of scope and visibility. In short, why can't I see any of the elements of Form1 (the base form generated by the "Windows...
1
by: The Menace | last post by:
I have a problem that I've been trying to figure out. I have several controls on the page and depending on the selection on the drop down list, the visibility is set to control to true (set to...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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,...
0
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,...
0
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...

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.