Wednesday, May 28, 2008

Invisible by style and invisible by attribute

For web page elements, when you set the display style attribute to none, the element is no longer on the screen. What you need to realise is that this is purely due to client side rendering from the browser - the elements are still send from the server to the client and has to be parsed by the browser.

For ASP.NET server side tags, setting the Visible attribute to false prevents the tag from being rendered into the (X)HTML generated for the page. The element never gets transmitted over the network, thus saving bandwidth.

When you're writing Javascript to turn items visible and invisible, you would still set the display style attribute because the element would have to be accessible from the client-side Javascript.

Basically, what this means is that if you're hiding an element to keep it from being used entirely (perhaps due to the user's role or something similar), set the Visible attribute to false and if you're just setting something hidden temporarily, use the display style attribute instead.

No comments: