1

I have a PlannerShiftView user control in the root folder of my ASP.NET web site. In my App_Code folder, I have a ShiftViewTemplate class that needs to instantiate a PlannerShiftView (for a TemplateField in a GridView). The problem is, the following code doesn't compile because the PlannerShiftView type is not available in what I deem to be the App_Code 'phantom namespace'.

Please can somebody explain to be what is happening here, as well as what to do. I know I can just move the ShiftViewTemplate out of App_Code, going against convention and without explantion, but that is something of a hollow victory.

1 Answer 1

2

ASP.Net websites do not compile into a single assembly, but into several ones. Therefore the code of your user control in not referenceable by the App_Code assembly.

The way I solved a similar case:

  • declare an IPlannerShiftView interface in App_Code or an external assembly

  • declare the PlannerShiftView control as implementing the IPlannerShiftView interface

  • instantiate the control using Page.LoadControl, and cast to interface

Sign up to request clarification or add additional context in comments.

1 Comment

Good idea, but a bit of work. Pity we have to do this. For now, I'm just taking the ShiftViewTemplate out of App_Code. It is UI code after all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.