hiding multiple items via codebehind efficiently

D

darrel

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
 
K

Karl Seguin

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!)
 
D

darrel

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top