Custom ListControl has no VS intellisense for <asp:ListItem>

Discussion in 'ASP .Net Building Controls' started by wjfamilia, Aug 31, 2007.

  1. wjfamilia

    wjfamilia Guest

    When I make a custom server control that inherits from ListControl or the
    other similar controls (DropDownList, CheckBoxList, etc.), I cannot get the
    child <asp:ListItem> control to show with the Visual Studio 2005
    intellisense. The control does render the correct results and you can even
    stop the build warning by wrapping the <asp:ListItem> children in
    <Items></Items>, BUT there is no intellisense! Why? What is needed to make my
    custom control's intellisense work like the ListControl's intellisense?

    Here is the custom control code I have up until now:

    //Custom
    CheckBoxControl:////////////////////////////////////////////////////////////////
    using System;
    using System.ComponentModel;
    using System.Collections;
    using System.Drawing.Design;
    using System.Security.Permissions;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;


    namespace NSP.Web.UI.WebControls
    {
    [AspNetHostingPermission(SecurityAction.LinkDemand, Level =
    AspNetHostingPermissionLevel.Minimal),
    AspNetHostingPermission(SecurityAction.InheritanceDemand, Level =
    AspNetHostingPermissionLevel.Minimal)]
    [ParseChildren(true, "asp:ListItem")]
    public class CheckBoxList : System.Web.UI.WebControls.CheckBoxList
    {
    [DefaultValue((string)null)]
    [Category("Default")]
    [PersistenceMode(PersistenceMode.InnerProperty)]
    [Description("The collection of items in the list.")]

    [Editor("System.Web.UI.Design.WebControls.ListItemsCollectionEditor,System.Design,
    Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
    typeof(UITypeEditor))]
    [MergableProperty(false)]
    public override ListItemCollection Items
    {
    get { return base.Items; }
    }

    [Bindable(true)]
    [Category("Data")]
    [DefaultValue("")]
    [Localizable(true)]
    public string CmsKey
    {
    get
    {

    string s = (string)ViewState[this.ID + "CheckBoxListCmsKey"];
    return ((s == null) ? String.Empty : s);
    }
    set
    {
    ViewState[this.ID + "CheckBoxListCmsKey"] = value;
    }
    }


    protected override void Render(HtmlTextWriter writer)
    {
    base.Render(writer);
    }
    }
    }

    //Implementation on Web
    Form////////////////////////////////////////////////////////
    <nsp:CheckBoxList ID="chklOptionPicker" runat="server">
    <asp:ListItem Text="Option #1" Value="1"></asp:ListItem>
    <asp:ListItem Text="Option #2" Value="2"></asp:ListItem>
    <asp:ListItem Text="Option #3" Value="3"></asp:ListItem>
    </nsp:CheckBoxList>


    This topic has been addressed on other forums, but no solution has been
    published.
    - http://forums.asp.net/t/1151562.aspx
    - http://forums.asp.net/t/979255.aspx

    Please help!

    --
    William J. Familia

    ----------------
    This post is a suggestion for Microsoft, and Microsoft responds to the
    suggestions with the most votes. To vote for this suggestion, click the "I
    Agree" button in the message pane. If you do not see the button, follow this
    link to open the suggestion in the Microsoft Web-based Newsreader and then
    click "I Agree" in the message pane.

    http://www.microsoft.com/communitie...blic.dotnet.framework.aspnet.buildingcontrols
     
    wjfamilia, Aug 31, 2007
    #1
    1. Advertising

  2. wjfamilia

    Teemu Keiski Guest

    Issue simply is that asp:ListItem is ListItem class in
    System.Web.UI.WebControls namespace. It's a limitation in VS2005 that the
    items related to a control should exist in same namespace. E.g type of the
    Items property and the ListItem itself should be their own types (ListItem
    is sealed so it requires writing it from scratch)

    I've blogged about it in the past:
    http://aspadvice.com/blogs/joteke/archive/2006/01/27/14886.aspx

    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net


    "wjfamilia" <> wrote in message
    news:...
    > When I make a custom server control that inherits from ListControl or the
    > other similar controls (DropDownList, CheckBoxList, etc.), I cannot get
    > the
    > child <asp:ListItem> control to show with the Visual Studio 2005
    > intellisense. The control does render the correct results and you can even
    > stop the build warning by wrapping the <asp:ListItem> children in
    > <Items></Items>, BUT there is no intellisense! Why? What is needed to make
    > my
    > custom control's intellisense work like the ListControl's intellisense?
    >
    > Here is the custom control code I have up until now:
    >
    > //Custom
    > CheckBoxControl:////////////////////////////////////////////////////////////////
    > using System;
    > using System.ComponentModel;
    > using System.Collections;
    > using System.Drawing.Design;
    > using System.Security.Permissions;
    > using System.Web;
    > using System.Web.UI;
    > using System.Web.UI.WebControls;
    >
    >
    > namespace NSP.Web.UI.WebControls
    > {
    > [AspNetHostingPermission(SecurityAction.LinkDemand, Level =
    > AspNetHostingPermissionLevel.Minimal),
    > AspNetHostingPermission(SecurityAction.InheritanceDemand, Level =
    > AspNetHostingPermissionLevel.Minimal)]
    > [ParseChildren(true, "asp:ListItem")]
    > public class CheckBoxList : System.Web.UI.WebControls.CheckBoxList
    > {
    > [DefaultValue((string)null)]
    > [Category("Default")]
    > [PersistenceMode(PersistenceMode.InnerProperty)]
    > [Description("The collection of items in the list.")]
    >
    > [Editor("System.Web.UI.Design.WebControls.ListItemsCollectionEditor,System.Design,
    > Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
    > typeof(UITypeEditor))]
    > [MergableProperty(false)]
    > public override ListItemCollection Items
    > {
    > get { return base.Items; }
    > }
    >
    > [Bindable(true)]
    > [Category("Data")]
    > [DefaultValue("")]
    > [Localizable(true)]
    > public string CmsKey
    > {
    > get
    > {
    >
    > string s = (string)ViewState[this.ID +
    > "CheckBoxListCmsKey"];
    > return ((s == null) ? String.Empty : s);
    > }
    > set
    > {
    > ViewState[this.ID + "CheckBoxListCmsKey"] = value;
    > }
    > }
    >
    >
    > protected override void Render(HtmlTextWriter writer)
    > {
    > base.Render(writer);
    > }
    > }
    > }
    >
    > //Implementation on Web
    > Form////////////////////////////////////////////////////////
    > <nsp:CheckBoxList ID="chklOptionPicker" runat="server">
    > <asp:ListItem Text="Option #1" Value="1"></asp:ListItem>
    > <asp:ListItem Text="Option #2" Value="2"></asp:ListItem>
    > <asp:ListItem Text="Option #3" Value="3"></asp:ListItem>
    > </nsp:CheckBoxList>
    >
    >
    > This topic has been addressed on other forums, but no solution has been
    > published.
    > - http://forums.asp.net/t/1151562.aspx
    > - http://forums.asp.net/t/979255.aspx
    >
    > Please help!
    >
    > --
    > William J. Familia
    >
    > ----------------
    > This post is a suggestion for Microsoft, and Microsoft responds to the
    > suggestions with the most votes. To vote for this suggestion, click the "I
    > Agree" button in the message pane. If you do not see the button, follow
    > this
    > link to open the suggestion in the Microsoft Web-based Newsreader and then
    > click "I Agree" in the message pane.
    >
    > http://www.microsoft.com/communitie...blic.dotnet.framework.aspnet.buildingcontrols
     
    Teemu Keiski, Sep 1, 2007
    #2
    1. Advertising

  3. wjfamilia

    Teemu Keiski Guest

    To add, of course you could put your own control to
    System.Web.UI.WebControls namespace but I think MS doesn't recommend that
    approach.


    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net



    "wjfamilia" <> wrote in message
    news:...
    > When I make a custom server control that inherits from ListControl or the
    > other similar controls (DropDownList, CheckBoxList, etc.), I cannot get
    > the
    > child <asp:ListItem> control to show with the Visual Studio 2005
    > intellisense. The control does render the correct results and you can even
    > stop the build warning by wrapping the <asp:ListItem> children in
    > <Items></Items>, BUT there is no intellisense! Why? What is needed to make
    > my
    > custom control's intellisense work like the ListControl's intellisense?
    >
    > Here is the custom control code I have up until now:
    >
    > //Custom
    > CheckBoxControl:////////////////////////////////////////////////////////////////
    > using System;
    > using System.ComponentModel;
    > using System.Collections;
    > using System.Drawing.Design;
    > using System.Security.Permissions;
    > using System.Web;
    > using System.Web.UI;
    > using System.Web.UI.WebControls;
    >
    >
    > namespace NSP.Web.UI.WebControls
    > {
    > [AspNetHostingPermission(SecurityAction.LinkDemand, Level =
    > AspNetHostingPermissionLevel.Minimal),
    > AspNetHostingPermission(SecurityAction.InheritanceDemand, Level =
    > AspNetHostingPermissionLevel.Minimal)]
    > [ParseChildren(true, "asp:ListItem")]
    > public class CheckBoxList : System.Web.UI.WebControls.CheckBoxList
    > {
    > [DefaultValue((string)null)]
    > [Category("Default")]
    > [PersistenceMode(PersistenceMode.InnerProperty)]
    > [Description("The collection of items in the list.")]
    >
    > [Editor("System.Web.UI.Design.WebControls.ListItemsCollectionEditor,System.Design,
    > Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
    > typeof(UITypeEditor))]
    > [MergableProperty(false)]
    > public override ListItemCollection Items
    > {
    > get { return base.Items; }
    > }
    >
    > [Bindable(true)]
    > [Category("Data")]
    > [DefaultValue("")]
    > [Localizable(true)]
    > public string CmsKey
    > {
    > get
    > {
    >
    > string s = (string)ViewState[this.ID +
    > "CheckBoxListCmsKey"];
    > return ((s == null) ? String.Empty : s);
    > }
    > set
    > {
    > ViewState[this.ID + "CheckBoxListCmsKey"] = value;
    > }
    > }
    >
    >
    > protected override void Render(HtmlTextWriter writer)
    > {
    > base.Render(writer);
    > }
    > }
    > }
    >
    > //Implementation on Web
    > Form////////////////////////////////////////////////////////
    > <nsp:CheckBoxList ID="chklOptionPicker" runat="server">
    > <asp:ListItem Text="Option #1" Value="1"></asp:ListItem>
    > <asp:ListItem Text="Option #2" Value="2"></asp:ListItem>
    > <asp:ListItem Text="Option #3" Value="3"></asp:ListItem>
    > </nsp:CheckBoxList>
    >
    >
    > This topic has been addressed on other forums, but no solution has been
    > published.
    > - http://forums.asp.net/t/1151562.aspx
    > - http://forums.asp.net/t/979255.aspx
    >
    > Please help!
    >
    > --
    > William J. Familia
    >
    > ----------------
    > This post is a suggestion for Microsoft, and Microsoft responds to the
    > suggestions with the most votes. To vote for this suggestion, click the "I
    > Agree" button in the message pane. If you do not see the button, follow
    > this
    > link to open the suggestion in the Microsoft Web-based Newsreader and then
    > click "I Agree" in the message pane.
    >
    > http://www.microsoft.com/communitie...blic.dotnet.framework.aspnet.buildingcontrols
     
    Teemu Keiski, Sep 1, 2007
    #3
    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. Mad Scientist Jr
    Replies:
    2
    Views:
    470
    Mad Scientist Jr
    Jun 29, 2004
  2. Jim in Arizona
    Replies:
    7
    Views:
    946
    Badass Scotsman
    Nov 22, 2006
  3. Scott Blood

    Custom ListControl OnFocus Event not working

    Scott Blood, Jul 31, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    161
    Scott Blood
    Jul 31, 2006
  4. Dave
    Replies:
    0
    Views:
    929
  5. Chris Burge

    Inherit from a custom ListControl

    Chris Burge, Dec 23, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    257
    Chris Burge
    Dec 23, 2005
Loading...

Share This Page