Composite control not appearing in toolbar...

Discussion in 'ASP .Net Building Controls' started by Griff, Oct 9, 2006.

  1. Griff

    Griff Guest

    Hi - I'm just experimenting and following the example in:
    http://msdn2.microsoft.com/en-us/library/ms379565.aspx

    I have a solution that has my controls project and a "test" web project.

    When I build the controls project, the control that inherits from
    "WebControls" appears fine in the toolbox, but the one that inherits from
    "CompositeControl" does not appear.

    Code for this control is below (just in case I've deviated from the MSDN
    example and not spotted it).

    Thanks for your help.

    Griff
    ------------

    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 WebControlLibraryPrototypeA
    {
    [DefaultProperty("Prompt")]
    [ToolboxData("<{0}:AgeCollector runat=server></{0}:AgeCollector>")]
    public class AgeCollector : CompositeControl
    {
    [Bindable(true)]
    [Category("Appearance")]
    [DefaultValue("Please enter your date of birth:")]
    [Description("Text to prompt user with")]
    [Localizable(true)]
    public virtual string Prompt
    {
    get
    {
    String s = (String)ViewState["Prompt"];
    return ((s == null) ? String.Empty : s);
    }

    set
    {
    ViewState["Prompt"] = value;
    }
    }

    [Bindable(true)]
    [Category("Appearance")]
    [Description("Date of birth input area")]
    public virtual DateTime DateOfBirth
    {
    get
    {
    object o = ViewState["DateOfBirth"];
    return (o == null) ? DateTime.Now : (DateTime)o;
    }
    set
    {
    ViewState["DateOfBirth"] = value;
    }
    }

    protected override void CreateChildControls()
    {
    Label lab1 = new Label();
    lab1.Text = Prompt;
    lab1.ForeColor = this.ForeColor;
    this.Controls.Add(lab1);

    Literal lit = new Literal();
    lit.Text = "<br/>";
    this.Controls.Add(lit);

    TextBox tb = new TextBox();
    tb.ID = "tb1";
    tb.Text = DateOfBirth.ToString();
    this.Controls.Add(tb);

    base.CreateChildControls();
    }
    }
    }
     
    Griff, Oct 9, 2006
    #1
    1. Advertising

  2. Griff

    Griff Guest

    Bit more info...if I right click in the toolbox and chose "show all" then
    this control appears, albeit greyed out. It's as if it compiled
    successfully but can't be used.
     
    Griff, Oct 9, 2006
    #2
    1. Advertising

  3. Be sure you have your namespace set properly in the AssemblyInfo.

    [assembly: TagPrefix("CustomNamespace.Controls", "cnc")]

    It should match up with your controls.

    And sometimes Visual Studio needs a restart. There are lots of bugs in
    VS which have been addressed by the SP1 Beta.

    You can get that beta here...

    http://connect.microsoft.com/visualstudio

    Brennan Stehling
    http://brennan.offwhite.net/blog/

    Griff wrote:
    > Hi - I'm just experimenting and following the example in:
    > http://msdn2.microsoft.com/en-us/library/ms379565.aspx
    >
    > I have a solution that has my controls project and a "test" web project.
    >
    > When I build the controls project, the control that inherits from
    > "WebControls" appears fine in the toolbox, but the one that inherits from
    > "CompositeControl" does not appear.
    >
    > Code for this control is below (just in case I've deviated from the MSDN
    > example and not spotted it).
    >
    > Thanks for your help.
    >
    > Griff
    > ------------
    >
    > 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 WebControlLibraryPrototypeA
    > {
    > [DefaultProperty("Prompt")]
    > [ToolboxData("<{0}:AgeCollector runat=server></{0}:AgeCollector>")]
    > public class AgeCollector : CompositeControl
    > {
    > [Bindable(true)]
    > [Category("Appearance")]
    > [DefaultValue("Please enter your date of birth:")]
    > [Description("Text to prompt user with")]
    > [Localizable(true)]
    > public virtual string Prompt
    > {
    > get
    > {
    > String s = (String)ViewState["Prompt"];
    > return ((s == null) ? String.Empty : s);
    > }
    >
    > set
    > {
    > ViewState["Prompt"] = value;
    > }
    > }
    >
    > [Bindable(true)]
    > [Category("Appearance")]
    > [Description("Date of birth input area")]
    > public virtual DateTime DateOfBirth
    > {
    > get
    > {
    > object o = ViewState["DateOfBirth"];
    > return (o == null) ? DateTime.Now : (DateTime)o;
    > }
    > set
    > {
    > ViewState["DateOfBirth"] = value;
    > }
    > }
    >
    > protected override void CreateChildControls()
    > {
    > Label lab1 = new Label();
    > lab1.Text = Prompt;
    > lab1.ForeColor = this.ForeColor;
    > this.Controls.Add(lab1);
    >
    > Literal lit = new Literal();
    > lit.Text = "<br/>";
    > this.Controls.Add(lit);
    >
    > TextBox tb = new TextBox();
    > tb.ID = "tb1";
    > tb.Text = DateOfBirth.ToString();
    > this.Controls.Add(tb);
    >
    > base.CreateChildControls();
    > }
    > }
    > }
     
    Brennan Stehling, Oct 9, 2006
    #3
  4. Griff

    Griff Guest

    Hi Brennan

    I'm not completely convinced that there is a problem with the namespaces -
    the other controls that inherit from WebControl within the same control
    library all appear. However, I did explicitly add it to the AssemblyInfo
    (and "Using System.Web.UI" but to no avail.

    I'll look into SP1 beta, though again I'm not that happy about using beta
    software. If it is a problem with the IDE then this tells me one of two
    things:
    a) there are a lot of people writing composite controls that are
    experiencing the same problem and PRESUMABLY have found a way around this
    problem before SP1Beta was released, or
    b) there aren't that many developers creating composite controls....

    I'm still hoping that it's just a silly mistake on my part....

    Griff
     
    Griff, Oct 10, 2006
    #4
  5. Griff

    PeterKellner Guest

    On 9 Oct 2006 13:16:22 -0700, "Brennan Stehling" <>
    wrote:

    >Be sure you have your namespace set properly in the AssemblyInfo.
    >
    >[assembly: TagPrefix("CustomNamespace.Controls", "cnc")]
    >
    >It should match up with your controls.
    >


    Hi,

    I just installed beta1 and still have the same problem. I've been
    wrestling with this for a long time and I know I have the above
    assembly correct. Any other ideas? It seems Microsoft knows how to
    make there controls appear in the toolbar. What can I do to make mine
    appear?
    Peter Kellner
    http://peterkellner.net
     
    PeterKellner, Oct 15, 2006
    #5
  6. You can always add the manually.

    Brennan Stehling
    http://brennan.offwhite.net/blog/

    PeterKellner wrote:
    > On 9 Oct 2006 13:16:22 -0700, "Brennan Stehling" <>
    > wrote:
    >
    > >Be sure you have your namespace set properly in the AssemblyInfo.
    > >
    > >[assembly: TagPrefix("CustomNamespace.Controls", "cnc")]
    > >
    > >It should match up with your controls.
    > >

    >
    > Hi,
    >
    > I just installed beta1 and still have the same problem. I've been
    > wrestling with this for a long time and I know I have the above
    > assembly correct. Any other ideas? It seems Microsoft knows how to
    > make there controls appear in the toolbar. What can I do to make mine
    > appear?
    > Peter Kellner
    > http://peterkellner.net
     
    Brennan Stehling, Oct 18, 2006
    #6
    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,696
    sleigh
    Feb 12, 2004
  2. King Kong

    Composite Control with Datagrid and Microsoft IE Toolbar

    King Kong, Dec 8, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    138
    King Kong
    Dec 8, 2004
  3. King Kong

    Datagrid and IE Control Toolbar Composite Control

    King Kong, Dec 20, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    142
    King Kong
    Dec 20, 2004
  4. Chad
    Replies:
    0
    Views:
    231
  5. pcouas
    Replies:
    0
    Views:
    263
    pcouas
    Feb 19, 2007
Loading...

Share This Page