hiding multiple items via codebehind efficiently

Discussion in 'ASP .Net' started by darrel, Aug 9, 2005.

  1. darrel

    darrel Guest

    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
     
    darrel, Aug 9, 2005
    #1
    1. Advertising

  2. darrel

    Karl Seguin Guest

    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" <> wrote in message
    news:...
    > 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
    >
    >
     
    Karl Seguin, Aug 9, 2005
    #2
    1. Advertising

  3. darrel

    darrel Guest

    > 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
     
    darrel, Aug 9, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Livin
    Replies:
    5
    Views:
    323
    Ben Sizer
    Jan 18, 2006
  2. sasuke
    Replies:
    5
    Views:
    2,027
    Tom Anderson
    Jul 6, 2008
  3. Brad
    Replies:
    7
    Views:
    1,300
    Jorgen Grahn
    Jun 25, 2010
  4. ela
    Replies:
    12
    Views:
    350
    Uri Guttman
    Apr 6, 2009
  5. Ste
    Replies:
    41
    Views:
    811
    Thomas 'PointedEars' Lahn
    Aug 1, 2007
Loading...

Share This Page