Pages

Thursday, September 5, 2013

Use ASP.NET's Visible property to do more than just hide the content (ASP.NET)

If you've explored ASP.NET's server controls, you've probably run across the built-in Visible property. At first, you may wonder how it's different from the CSS visibility setting. After all, both settings effectively make the relevant page element visible or invisible. The difference is in the rendering.

In CSS, to make an element invisible, you set the element's visibility property to hidden. With this setting in place, the browser won't display the related content. With ASP.NET's Visible property, setting it to False produces the same end results. However, keep in mind that because CSS is only concerned with the client-side display, it doesn't prevent the invisible content from actually being sent to the browser (or other user agent). A server control's Visible property, on the other hand, dictates whether ASP.NET will even send rendered content to the browser. As a result, if you set a control's Visible property to False, the final rendered HTML won't contain any tags related to the server control. This behavior is critical when you need to conditionally send content to the browser—for instance, based on the user’s authentication level. If any old script-kiddie can view a Web page's source code to get sensitive information, hiding it from display doesn't do you much good.



No comments:

Post a Comment

Note: Only a member of this blog may post a comment.