Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > hiding multiple items via codebehind efficiently

Reply
Thread Tools

hiding multiple items via codebehind efficiently

 
 
darrel
Guest
Posts: n/a
 
      08-09-2005
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


 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      08-09-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
darrel
Guest
Posts: n/a
 
      08-09-2005
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing Multiple Strings More Efficiently Brad C++ 7 06-25-2010 07:27 AM
resolve single line with multiple items into mutliple lines, single items ela Perl Misc 12 04-06-2009 06:47 PM
Efficiently concatenating contents of multiple files sasuke Java 5 07-06-2008 02:27 AM
Script for Hiding/Un-Hiding Text On Click Ste Javascript 41 08-01-2007 02:35 PM
search multiple dictionaries efficiently? Livin Python 5 01-18-2006 09:18 AM



Advertisments