User control and collection of friendly objects (like ListBox and ListItems, but with List <Class>) on .ASPX
I was wondering for a long time how to make a public property for a user control that works as a native element of a collection of .NET objects (for example, ListBox and ListItems):
<asp:ListBox blablabla> <asp:ListItem></asp:ListItem> <- Inline item collection... </asp:ListBox> I browsed the web, but without any success. I think that this should be any type of attribute that I need to add to the property, the OR interface, which should be inherited by the user control, but has no idea about it and thought about it for a long time.
I have to work on a user control, but Visual Studio did not recognize it as a valid collection of elements.
Say we have this userControl:
public partial class userControls_Blablabla : System.Web.UI.UserControl { public List<configItem> ConfigItem {get; set; } blablabla...rest logic here... } public class configItem { public string Name {get; set;} public string Url {get; set;} public string Color {get; set;} blablabla...rest logic here... } How to do this in order to be able to do something similar in the .ASPX Visual Studio editor and recognize its Intellisense?
<User_Control:userControls_Blablabla ID="blablabla" ...blablabla....> <ConfigItem Name="1" Url="...." Color="..." /> <ConfigItem Name="2" Url="...." Color="..." /> <ConfigItem Name="3" Url="...." Color="..." /> </User_Control:userControls_Blablabla> Sorry for my English, I know this is not very good.
Thanks in advance!
You need to decorate the control and its properties with enough information that the designer can get in detail during development. Have you checked this link?
You can put a list of your type in a management class and decorate PersistenceModeAttribute.
[PersistenceMode(PersistenceMode.InnerProperty)] public List<configItem> ConfigItem { get; set; } The best example:
Just like adding - the link really helped. The only thing I want to add is how you can directly register it on your website so that intellisense picks it up and doesn't have another assembly.
Create the classes as described, instead, if the rendering I override the OnInit method, as it is called earlier, and I can play some more with another support. 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 register them directly on your aspx pages or in your web configuration, depending on how often you 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" %>