473,499 Members | 1,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

hiding multiple items via codebehind efficiently

When showing/hiding items on the front end via codebehind, one normally just
sets the object to runat='server' and then set's its visibility to false.

This works fine. However, when I have a 'set' of items that are scattered
all around the page, having to explicitely set each individual item to
true/false can get a bit tedious. Is there a more efficient method for
hiding a variety of items at once?

I can do this via javascript if I set each object's class the same and then
reference that, but I'd rather control this server side.

-Darrel
Nov 19 '05 #1
2 1197
I take it you say "scattered" because you can't just put them in a
placeholder and set IT's visibility...

There actually is a really good and simple solution to this, create a custom
server control, who's logic is to determine whether it's visible or not.
For example, if you don't want a textbox to be displayed if the current user
doesn't had "Write" mode, you would do:

public class WriteTextBox : TextBox //stupid name
{
public override Render(HtmlTextWriter writer)
{
if ( ! User.CurrentUser.InInRole("Write")
{
Visibible = false;
}
}
}
the above code is fictional, but that's how I'd approach it...

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"darrel" <no*****@hotmail.com> wrote in message
news:ek**************@TK2MSFTNGP10.phx.gbl...
When showing/hiding items on the front end via codebehind, one normally
just
sets the object to runat='server' and then set's its visibility to false.

This works fine. However, when I have a 'set' of items that are scattered
all around the page, having to explicitely set each individual item to
true/false can get a bit tedious. Is there a more efficient method for
hiding a variety of items at once?

I can do this via javascript if I set each object's class the same and
then
reference that, but I'd rather control this server side.

-Darrel

Nov 19 '05 #2
> I take it you say "scattered" because you can't just put them in a
placeholder and set IT's visibility...
Right. They're usually all sub-items of a variety of parent containers.
There actually is a really good and simple solution to this, create a custom server control, who's logic is to determine whether it's visible or not.
For example, if you don't want a textbox to be displayed if the current user doesn't had "Write" mode, you would do:

public class WriteTextBox : TextBox //stupid name
{
public override Render(HtmlTextWriter writer)
{
if ( ! User.CurrentUser.InInRole("Write")
{
Visibible = false;
}
}
}
the above code is fictional, but that's how I'd approach it...


Hmm...I've never done server controls. I'll take a look at that!

-Darrel
Nov 19 '05 #3

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

Similar topics

5
2164
by: Amir S. | last post by:
Hi, I'm a newbie to C++ (2 weeks into the course). We were given this assignment to write some code that reads a set of integers (grades) from a file (filename passed by console), outputs them...
3
5692
by: Gandalf | last post by:
I wish to apply different styles to items in a DropDownList. However, any styles applied in the codebehind (using the ListItem.Addtributes property) do not get rendered. This is an old question but...
2
2241
by: Antoine | last post by:
I would like to construct my own list of items in a grid/ table/ item list layout but I have a problem. I want to add a sort of index row based on time, such as there might be blank values. Sure...
10
3264
by: Adam Clauss | last post by:
I have a page containing a list box. This list may contain duplicate items - in which the ORDER is important. ex: a b b a is significant as compared to: b
0
3447
by: funphxnaz | last post by:
I'm using ASP.net 2.0 (VWD) and I'd like to programmatically hide a DataList row based on a Repeater nested in the DataList. Specifically, if the Repeater.Items.Count = 0, I'd like the entire...
11
3131
by: Ranginald | last post by:
This question is about how to handle an .aspx page that references multiple methods and where to store these methods (e.g. one codefile or multiple codefiles). PREFACE ======== I have a simple...
9
2817
by: Daz | last post by:
Hello people! (This post is best viewed using a monospace font). I need to create a class, which holds 4 elements: std::string ItemName int Calories int Weight int Density
3
1639
by: RSH | last post by:
Hi, I am having this very bizarre occurance with 4 dropdown lists on my ASP .Net page. Each control has its own unique id. When the user selects a value from each of the dropdownlists it is...
4
1977
by: duncfair | last post by:
asp.net 2.0 and language is c# I need to add a single checkbox on an aspx page based on evaluating two aspects of the items the customer has placed in the shopping cart. The price must be $100...
0
7134
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
7014
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
7180
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
7395
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...
0
5485
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
4609
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...
0
3108
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.