Weird problem in ASP.NET again... With a weird solution:
In my apps I always have a folder UserControls where I put UserControls (not custom or server controls) that I use throughout the site. Examples are a date textbox with validation, formatted labels, upload fields, toggled image buttons, error message labels, etc. I register all these controls globally in the web.config pages section, like this:
<add tagPrefix="myapp" tagName="WebUserControl1"
<add tagPrefix="myapp" tagName="WebUserControl2"
The problem is that some user controls also use another user control from that same folder, which leads to the following ASP.NET parser error:
Parser Error Message: The page '/UserControls/WebUserControl1.ascx' cannot use the user control '/UserControls/WebUserControl2.ascx', because it is registered in web.config and lives in the same directory as the page.
The solution for that is to add a @Register directive to WebUserControl1.ascx like this:
<%@ Register TagPrefix="myapp" TagName="WebUserControl2" Src="~/UserControls/WebUserControl2.ascx" %>
But now I get the error from the blog post title, so if I add new controls to the user control, the designer file is not updated and I cannot access these in code behind (unless I update the designer file manually - NOT).
The key to resolve is to either pick a different TagPrefix or TagName in the @Register directive and use it like that, e.g.:
<%@ Register TagPrefix="myappLocal" TagName="WebUserControl2" Src="~/UserControls/WebUserControl2.ascx" %>
<myappLocal:WebUserControl2 runat="server" />
<%@ Register TagPrefix="myapp" TagName="WebUserControl2Local" Src="~/UserControls/WebUserControl2.ascx" %>
<myapp:WebUserControl2Local runat="server" />
Now the designer file keeps updating...