473,666 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setup visibility of controls programmaticall y

Hello!

I am working on an on-line ASP.Net library.
I would like to set up the visibility of some controls programmaticall y.
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.EventArg s) 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_Contro l.ID, 6) = "admin_" Then
Page.FindContro l(obj_Control.I D)
obj_Control.Vis ible = 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 1417
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 programmaticall y.
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.EventArg s) 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_Contro l.ID, 6) = "admin_" Then
Page.FindContro l(obj_Control.I D)
obj_Control.Vis ible = 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******** ******@TK2MSFTN GP12.phx.gbl...
Hello!

I am working on an on-line ASP.Net library.
I would like to set up the visibility of some controls programmaticall y.
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.EventArg s) 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_Contro l.ID, 6) = "admin_" Then
Page.FindContro l(obj_Control.I D)
obj_Control.Vis ible = 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.FindContr ol" 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
5345
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 works. Now, I am wondering if there is any way to change the directory that the installer installs the files to. I want to be able to put my files in a specified directory (user specified is good, but i don't mind hardcoding the path either) and...
1
6388
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 loads. Is this possible? Using this code I can change the visibility from a link in the parent window: onClick="document.getElementById('controls').style.visibility='visible'"
8
4310
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 button at runtime: //----- Code snippet protected System.Web.UI.WebControls.PlaceHolder ImageHolder; private void Page_Load(object sender, System.EventArgs e)
6
2031
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 a straightforward recursive loop. Now - I'm really muddled by this - why does this: If TypeOf Ctl Is DropDownList Then Ctl.Visible = true End If
11
2619
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" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%> <table cellSpacing="0" cellPadding="0" border="0"> <colgroup span="1" align="left" width="50%"> </colgroup> <colgroup span="1" align="right" width="50%"> </colgroup>
0
3487
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 (http://msdn.microsoft.com/msdnmag/issues/04/11/CuttingEdge/) "The contents of a WizardStep can be dynamically adjusted and steps can be
3
2636
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 CssClass to them, or programmatically making the Visible/not Visible. If applied to a containing page, such a function would traverse all user controls statically and dynamically placed on the page, correct? Thanks,
2
1851
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 Application Project Wizard") from anywhere else in my project? For example, why can I not change the text of a TextBox control from Main() (which is, by default, in the Program class) even after I have set its visibility to public in Form1? Furthermore,...
1
1275
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 default visibility to false) of some controls. What I want though is to make the control go up if the visibility is set to true instead of "stacked". I hope I'm explaining my problem correctly. I wanted to make the controls more dynamic that is...
0
8445
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8871
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8640
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7386
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5664
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
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.