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
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