Register and Page directive in Visual Studio 2005
I am testing a Beta 2 application in a much more recent build. Turns out there were a number of problems. First, a user control that is dynamically loaded caused a compilation problem, saying the class the user control is based upon was not found. Part of this problem is related to how an ASP.NET 2.0 application is compiled. Rather than building the application into a single DLL dropped into the \bin folder, ASP.NET 2.0 compiles one or more pages into DLL's in a non-deterministic way. So, if the UserControl class ended up being compiled into the same DLL as the page using it, all is well. However, if the user control ends up being compiled into a different dll than the page, the page will not see it. I thought I had resolved this (and in fact, the app did compile in Beta 2) by adding a @ Reference directive for the user control. There was no declarative use of the user control on the page, so initially I did not have an @ Reference directive (and foolishly, had not registered the user control in Web.Config).
So, why did the @ Reference directive not work in the latest version of ASP.NET I am using? Apparently, my anal-retentive need to organize directives, placing the @ Register directive below the @ Page directive, was the cause. Moving the @ Register directives above the @ Page directive fixed the problem, and the compile proceeded further.
The final problem (one that I shake my head at) is that the casing of the name of the class needed to change. My declaration for the class is this:
public
partial class EditLookupData : System.Web.UI.UserControl However, I needed to reference it on a page as follows:
ASP.
editlookupdata_ascx Note the case difference. I got the all lower case casing from Intellisense.
The code now compiles, though I have not run it yet (I am traveling and have not installed the database on the machine I am playing with). More to follow as I actually run the application, likely tomorrow.