Monday, July 31, 2006

Many developers are accustomed to using ASP.NET’s Panel control to show or hide parts of a page. I see this often:

<table>
 <asp:Panel runat=”server” id=”pnlWrong” visible=”false”>
  <tr>
   <td>stuff to hide</td>
  </tr>
 </asp:Panel>
 <tr>
  <td>stuff to show</td>
 </tr>
</table>

If you view source in the browser when the Panel is hidden, everything looks as you would expect…

<table>
 <tr>
  <td>stuff to show</td>
 </tr>
</table>

However, if you make the Panel visible, you will get something like this:

<table>
 <div id=”ct100_ pnlWrong”>
  <tr>
   <td>stuff to hide</td>
  </tr>
 </div>
 <tr>
  <td>stuff to show</td>
 </tr>
</table>

Notice the div tags that make this markup invalid. Adaptive browser rendering can make this worse if the Panel renders as a table.

The solution is simple. The best bet is to use PlaceHolder control instead, which is similar to Panel but without all of the display properties. You could also add the runat=”server” and id attributes to your table rows (or the table itself) and control the visibility that way.

posted at Monday, July 31, 2006 2:29:25 PM (Eastern Standard Time, UTC-05:00)
#    Comments [0]  |  Trackback
Search
Archives
<July 2008>
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

Syndication
RSS 2.0 Atom 1.0
Support
Navigation
Categories
Blogroll

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008, Avesh Jain

Sign In