Building Composite Controls with the toolbox

Discussion in 'ASP .Net Building Controls' started by None, Feb 3, 2006.

  1. None

    None Guest

    I'm building my first ASP.NET 2.0 app. I'm familiar with 1.0 and 1.1 and
    have read various books, so I'm not a complete beginner. However, I've
    become stumped on something that I feel should be easy, but is causing me
    some confusion. I've searched on the net, but can't find a resolution.

    I'm trying to build a server control that inherits from CompositeControl,
    I would like it to be visible in the toolbox.

    Here is exactly what I'm doing.

    1. Create a new "ASP.NET 2.0 Web Site" (c#)
    2. Add another new project (c#\windows\web control library)
    3. Open the class "WebCustomControl1.cs"
    4. Modify the class (notice I've changed the base blass):

    ----------------
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace WebControlLibrary1
    {
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:WebCustomControl1 runat=server></
    {0}:WebCustomControl1>")]
    public class WebCustomControl1 : CompositeControl
    {
    protected TextBox tb = new TextBox();

    [Bindable(true)]
    [Category("Appearance")]
    [DefaultValue("")]
    [Localizable(true)]
    public string Text
    {
    get
    {
    return tb.Text;
    }

    set
    {
    tb.Text = value;
    }
    }

    protected override void CreateChildControls()
    {
    base.Controls.Add(tb);
    base.CreateChildControls();
    }

    }
    }
    ------------------
    5. Compile the solution

    6. In the web site project add a reference to the web control library
    project (This adds a bin folder to my website with the DLL inside)

    7. One problem, there's no item in the toolbox when opening a web page
    like default.aspx.

    8. If I add a new Web custom control to the web control library project
    and recompile, then open default.aspx. the new control
    (webcustomcontrol2) is in the toolbox.

    9. I can drag it on the form I get the HTML
    <cc1:WebCustomControl2 ID="WebCustomControl2_1" runat="server" />
    I can rename it to:
    <cc1:WebCustomControl1 ID="WebCustomControl2_1" runat="server" />
    This displays the text box from my CompositeControl and it works fine.



    Why can't I see the composite control in the toolbox?

    One strange thing I found, If I right click on the webcontrol project and
    select "Remove" then add it in again. Both controls are visible in the
    toolbox. However is I exit visual studio and restart it's gone again.

    I don't any problems with the second control (based on WebControl) only
    the first control (based on CompositeControl)

    Do I need more code in the Composite control? I feel I may be missing
    something obvious.

    Please please help.

    Thanks,
    Craig
     
    None, Feb 3, 2006
    #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. sleigh
    Replies:
    1
    Views:
    2,736
    sleigh
    Feb 12, 2004
  2. Emjay

    Question on building composite controls

    Emjay, Dec 3, 2003, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    109
    Emjay
    Dec 3, 2003
  3. Chad
    Replies:
    0
    Views:
    252
  4. Sasha

    Example of Building Composite Controls in ASP.NET 2.0

    Sasha, May 31, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    149
    Sasha
    May 31, 2006
  5. Mike

    Composite vs non composite Controls

    Mike, Mar 10, 2005, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    290
    Sundararajan
    Mar 11, 2005
Loading...

Share This Page