I have an aspx page where I would like to add a link to a user control. The user control is stored in a separate assembly and loaded at run time. After entering the user control, it should be loaded into the page control collection.
Everything seems to be working fine, waiting for the control to be added to the page. There is no error, but the user interface for the control is not displayed.
Global.asax.cs
protected override Ninject.IKernel CreateKernel()
{
var modules = new INinjectModule[] { new MyDefaultModule() };
var kernel = new StandardKernel(modules);
kernel.Load("ExternalAssembly.dll");
return kernel;
}
and this is how the external module is defined in another assembly:
public class ExternalModule : NinjectModule
{
public ExternalModule() { }
public override void Load()
{
Bind<IView>().To<controls_MyCustomUserControlView>();
}
}
The debugger shows that when the application starts, Load is called on the external module, and the dependency is entered on the page.
public partial class admin_MainPage : PageBase
{
[Inject]
public IView Views { get; set; }
( ) . , Ninject? , , .
aspx
var c = (UserControl)Views;
var view = MultiView1.GetActiveView().Controls.Add(c);
MultiView1.GetActiveView().Controls.Add(new Label() { Text = "Nice view you got here..." });
, , view/user:
public partial class controls_MyCustomUserControlView : UserControl, IView
{
}
:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MyCustomUserControlView.ascx.cs" Inherits="controls_MyCustomUserControlView" %>
<asp:Label Text="Wow, what a view!" runat="server" />