Tuesday, August 08, 2006

When ASP.NET 2.0 came out, I really loved being able to declare commonly used user controls in web.config. Anything I could do to keep my pages leaner and cleaner put a smile on my face. Unfortunately, the Web Application Projects add-in has a problem identifying the type of user controls defined in web.config... they are generated as System.Web.UI.UserControl. This is a known bug and should be fixed in the VS 2005 service pack. Keep this in mind if you are moving to the Web Application Project model.

Below are the steps to reproduce the problem from my post on the ASP.net forums:


When we register our User Controls in web.config instead of on the page, we found the type is generated as System.Web.UI.UserControl instead of the type of the actual user control. Here are the steps to reproduce this problem:

1) Create a new Web Site
2) Create a folder called Controls and add a user control to this folder (e.g., WebUserControl.ascx)
3) Add a web.config to the site
4) Add the control registration to the web.config. E.g.:

  <pages>
   <controls>
    <add tagPrefix="test" tagName="WebUserControl" src="~/Controls/WebUserControl.ascx"/>
   </controls>
  </pages>

5) Add an instance of the user control to default.aspx:

        <test:WebUserControl runat="server" ID="test" />

6) Add a Web Application Project to the solution. Delete default.aspx and web.config from the new project. Copy the Controls folder, Default.aspx, and web.config to the new project.

7) Right click on the new Web Application project and select "Convert To Web Application"

8) Take a look at Default.aspx.designer.cs. We expect to see:

    protected Controls_WebUserControl test;

  But instead we get:

    protected System.Web.UI.UserControl test;

Let's try moving the control registration to the page itself.
 
9) Remove the "pages" section from the web.config

10) Add the control registration to default.aspx:

<%@ Register TagPrefix="test" TagName="WebUserControl" Src="~/Controls/WebUserControl.ascx" %>

11) Delete Default.aspx.designer.cs. Right click Default.aspx and select "Convert to Web Application"

12) Take a look at Default.aspx.designer.cs. We get what we expected:

     protected Controls_WebUserControl test123;

So basically whenever we register controls in our web.config, we get the wrong type in the .designer.cs file.

kick it on DotNetKicks.com
posted at Tuesday, August 08, 2006 10:06:15 AM (Eastern Standard Time, UTC-05:00)
#    Comments [0]  |  Trackback
 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