Use of ASP.NET user control in code results in 'defined in assembly not referenced' exception
I've got a user control which contains a number of other user controls.
I need programmatic access to some of the properties of one of the inner controls from the page which contains the outer control.
So, Page contains Outer Control contains Inner Control, and Page needs access to Inner Control's properties.
I could of course create properties in Outer Control which return the corresponding properties in Inner Control, but this would be tedious.
What I would like to do is add a property to Outer Control which returns Inner Control itself, so that Page can access its properties directly:
(In codebehind for Outer Control):
public UserControls_InnerControl InnerControl { get { return this.ctlInnerControl; } }
But when I build the website I get:
The type 'UserControls_InnerControl' is defined in an assembly that is not referenced. You must add a refere开发者_高级运维nce to assembly 'App_Web_fc5rstgb, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
What the hell? I work programmatically with instances of user controls all the time (for example, adding them dynamically to other controls) and I've never seen this before.
Is there anything I can do?
Edit: Interestingly, it's not the property in OuterControl which exposes InnerControl which is causing the exception. It's the code in Page which consumes this property that errors.
Try to add the following on the Page that is accessing he inner control:
<%@ Register Src="UserControls_InnerControl.ascx" TagName="uc" TagPrefix="uc1" %>
<%@ Reference Control="~/InnerControl.ascx" %>
Fix the paths as per your application.
Regards
精彩评论