NullReferenceException after turning ascx UserControl into reusable server control using Microsoft's tips
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:
- Create a website, add a usercontrol, add a Literal and set its text in the code-behind. Test it.
- Compile to fixed named assembly, non-updatable
- 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.
精彩评论