Add Dependent Assemblies to Custom Control

Discussion in 'ASP .Net Web Controls' started by Mauro Gagna, May 15, 2009.

  1. Mauro Gagna

    Mauro Gagna Guest

    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
    Mauro Gagna, May 15, 2009
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Garry
    Replies:
    0
    Views:
    396
    Garry
    Jul 14, 2003
  2. puzzlecracker
    Replies:
    1
    Views:
    507
    James Kanze
    Aug 7, 2008
  3. Matt Sokol
    Replies:
    2
    Views:
    365
    Theo Tillotson
    Aug 7, 2003
  4. Isai

    Dependent Properties in Custom Web Server Control

    Isai, Oct 9, 2007, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    770
  5. Robert Nicholson
    Replies:
    1
    Views:
    114
    Robert Nicholson
    Jan 2, 2007
Loading...

Share This Page