I have been wondering a long time how to do a public property for a User Control that work\'s like .NET native Item\'s collection Property (for Example, ListBox and ListItem
Just as an add on - the link above really helped. The only thing that I want to add is how you can directly register it in your website so that intellisense picks it up and without having a different assembly.
Create the classes as described - instead if the rendering i override the OnInit method, since it is called earlier and I can play some more with the other prop. Create 2 namespaces:
namespace x.Controls.Conference - add the class that derives from UserControl
{
public partial class SlideShow : System.Web.UI.UserControl{...}
}
namespace x.Controls.Conference.SlideShowUC - add here the base class of the collection item in the UC (Collection<Slide>)
{
public class Slide{...}
public class SlideCollectionEditor : CollectionEditor{...}
}
Now you can directly register them in your aspx pages or in the web config, depending on how often you will use the control.
WEB CONFIG
<add tagPrefix="ucSlideShow" tagName="SlideShow" src="~/x/Controls/Conference/SlideShow.ascx" />
<add tagPrefix="ucSlideShow" namespace="x.Controls.Conference.SlideShowUC" assembly="WebAssembly" />
PAGE
<%@ Register TagPrefix="ucSlideShow" TagName="SlideShow" src="~/x/Controls/Conference/SlideShow.ascx" %>
<%@ Register TagPrefix="ucSlideShow" namespace="x.Controls.Conference" assembly="WebAssembly" %>
You can place a list of your type in the control class and decorate with PersistenceModeAttribute.
[PersistenceMode(PersistenceMode.InnerProperty)]
public List<configItem> ConfigItem { get; set; }
An better example:
http://am-blog.no-ip.org/BlogEngine/post/2010/04/13/ASP-NET-Custom-Control-with-PersistenceModeInnerProperty-using-Server-Controls.aspx
You need to decorate the control and it's properties with sufficient information that the designer can pick up on details at design time. Have you checked this link?