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 Related posts:
Bug in Web Application Projects add-in User Controls
Tracked by:
"When not to use a Panel" (DotNetKicks.com) [Trackback]

Name
E-mail
Home page

Comment (Some html is allowed: )  

Enter the code shown (prevents robots):

Search
Archives
<September 2008>
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

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