Last post Nov 04, 2009 12:34 PM by ojm37
Nov 04, 2009 10:28 AM|ojm37|LINK
I have a Control in the App_Code directory that I'm using as a base-control for several child controls that all have many things in common, but need to do a few things different.
In App_Code, I have a control that starts with this:
Public Class OptionsBaseControl
'methods, controls, etc.
Then in another directory on the site, I have a UserControl that I want to create in the base-control. Any idea how I can get the base control to "see" the UserControl? If they were two UserControls, I would just add the "@ Reference" directive in the ascx
file of one control. However, a Control in App_Code doesn't have an ascx file.
I know I can use LoadControl(...) to get it in there, but then I want to be able to call methods on it (and use intellisense), but...
User control Server Control Reference
Nov 04, 2009 12:34 PM|ojm37|LINK
OK, This seems to be working so far: I created an Interface in app_code that then the control I'm loading with the LoadControl Implements.
So, the code in the base control looks like this:
Dim objLoadedControl as ILoadedControl
objLoadedControl = CType(LoadControl("~/path/LoadedControl.ascx"), ILoadedControl)
Me.Controls.Add( objLoadedControl )
While the code in the loaded control looks like this:
Partial Class LoadedControl
'Methods, properties, etc.
I haven't run this code yet, but the IDE isn't complaining about it and Intellisense is working (for the methods in the Interface).
Unless anyone knows of a better way?