Add Dependent Assemblies to Custom Control

M

Mauro Gagna

I make a Custom Control but when I use them with drag and drop from the
toolbox I need VS add all reference needed automatically.

This is the situation. I have a class MyNiceControl into a MyWebControls.dll
assembly.
Also I have a MyNiceControlToolboxItem where I think I can implement the
behavior what I want.

MyNiceControl use an object of the class called MyControl1 with inherits
from MyControlParent. All off them in different assemblies.

When I put MyNiceControl into an webform I need the project add a reference
to MyNiceControl assemblie, MyControl1 assemblie and MyControlParent
assemblie.

I make this code to do that.

[ToolboxData("<{0}:MyNiceControl runat=server></{0}: MyNiceControl >")]
[ToolboxItem(typeof(MyWebControls.MyNiceControlToolboxItem))]
public class MyNiceControl: WebControl
{
Private MyControl1 m_ctrl;
protected override void RenderContents(HtmlTextWriter output)
{
output.Write(“<table><tr><td>â€);
m_ctrl = new MyControl1();
string text = m_ctrl1.GenerateSomeStuff();
output.Write(text);
output.Write(“</td></tr><table>â€);
}

}

[Serializable]
internal class MyNiceControlToolboxItem: System.Drawing.Design.ToolboxItem
{

public MyNiceControlToolboxItem () : base() { }


private MyNiceControlToolboxItem (SerializationInfo info, StreamingContext
context)
: base(typeof(MyNiceControl))
{
Deserialize(info, context);
}

protected override IComponent[] CreateComponentsCore(IDesignerHost host)
{
ITypeResolutionService service1;
Assembly assembly1, assembly2;

IComponent component1;
IComponent[] componentArray1;

IContainer container1 = host.Container;
service1 =
((ITypeResolutionService)host.GetService(typeof(ITypeResolutionService)));

assembly1 = typeof(MyCtrls.MyControl1).Module.Assembly;
assembly2 = typeof(MyBaseCtrls.MyParentCtrl).Module.Assembly;

service1.ReferenceAssembly(assembly1.GetName());
service1.ReferenceAssembly(assembly1.GetName());

AssemblyName[] depends = this.DependentAssemblies;
List<AssemblyName> listDepends = new List<AssemblyName>();
listDepends.AddRange(depends);

listDepends.Add(assembly1.GetName());
listDepends.Add(assembly2.GetName());

this.DependentAssemblies = listDepends.ToArray();

component1 = new WUCFormularioCarga();
container1.Add(component1);
componentArray1 = new IComponent[] { component1 };

return componentArray1;
}
}

When I put this control into an aspx page in the page adds:
<%@ Register Assembly=" MyWebControls" Namespace=" MyWebControls "
TagPrefix="cc1" %>

And adds a reference to MyWebControls.dll, but nothing about the other
assemblies.

Any ideas?

Thanks in advance.

Mauro Gagna
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,818
Messages
2,569,736
Members
45,709
Latest member
DRISenaida

Latest Threads

Top