views:

154

answers:

0

A supposedly proven technique to turn UserControls of a website into reusable server controls while retaining the ability to use declarative code gives me a NullReferenceException on any reference of any control that's declared inside the ASCX code.

When calling the ASCX from the same project, this problem does not occur.

The idea is that the on-demand compilation of the declarative code of the controls is done (precompiled website). After applying aspnet_merge, the awkwardly named assemblies receive normal names, however, if this first step isn't working... What I did, in short:

  1. Create a website, add a usercontrol, add a Literal and set its text in the code-behind. Test it.
  2. Compile to fixed named assembly, non-updatable
  3. Take the output DLL, add them to another webite project and test them.

The last step gives me the null reference exception the minute I try to access any property of a declaratively initialized control from within that control (i.e., in the Page_Load in my case).

PS: Scott Guthrie explains the same technique here.