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.
