开发者

NullReferenceException after turning ascx UserControl into reusable server control using Microsoft's tips

开发者 https://www.devze.com 2022-12-19 09:14 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号