hiding multiple items via codebehind efficiently

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • darrel

    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


  • Karl Seguin

    #2
    Re: hiding multiple items via codebehind efficiently

    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(HtmlText Writer writer)
    {
    if ( ! User.CurrentUse r.InInRole("Wri te")
    {
    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" <notreal@hotmai l.com> wrote in message
    news:ekPfB2PnFH A.1372@TK2MSFTN GP10.phx.gbl...[color=blue]
    > 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
    >
    >[/color]


    Comment

    • darrel

      #3
      Re: hiding multiple items via codebehind efficiently

      > I take it you say "scattered" because you can't just put them in a[color=blue]
      > placeholder and set IT's visibility...[/color]

      Right. They're usually all sub-items of a variety of parent containers.
      [color=blue]
      > There actually is a really good and simple solution to this, create a[/color]
      custom[color=blue]
      > 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[/color]
      user[color=blue]
      > doesn't had "Write" mode, you would do:
      >
      > public class WriteTextBox : TextBox //stupid name
      > {
      > public override Render(HtmlText Writer writer)
      > {
      > if ( ! User.CurrentUse r.InInRole("Wri te")
      > {
      > Visibible = false;
      > }
      > }
      > }
      >
      >
      > the above code is fictional, but that's how I'd approach it...[/color]

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

      -Darrel


      Comment

      Working...