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

W

wjfamilia

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
 
T

Teemu Keiski

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 said:
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
 
T

Teemu Keiski

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top