![]() |
| |||||||
| S'inscrire | FAQ | Membres | Calendrier | Recherche | Messages du jour | Marquer les forums comme lus |
![]() |
| LinkBack | Outils de la discussion | Modes d'affichage |
| |||
| Hello, J'ai des soucis pour ajouter une propriété de type collection à un control dérivé. Tout fonctionne très bien quand j'hérite de Control à la place de Panel !! J'utilise VS 2003, .NET 3.5. Pour reproduire le problème, ajouter MyPanel à une page et ajouter un role dans AllowedRole. Fermer la page et ouvrir à nouveau : le contenu de la propriété à disparu... On voit bien dans le code HTML que la propriété n'est pas sérialisée. J'insiste sur le fait que ceci fonctionne très bien quand on hérite de "Control"... J'ai retourné internet mais je ne trouve aucune solution. Avez-vous une idée ? Cordialement,Ornette Voici le code : using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Collections; namespace MyControl { [ToolboxData("<{0}:MyPanel runat=server></{0}:MyPanel>")] [ParseChildren(true, "AllowedRoles")] [PersistChildren(false)] public class MyPanel : System.Web.UI.WebControls.Panel // <=== // Works with public class MyPanel : Control !!!!! { public MyPanel() : base() { } [Category("MyProperties")] [NotifyParentProperty(true)] [DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)] [PersistenceMode(PersistenceMode.InnerProperty)] public RoleCollection AllowedRoles { get { return roles; } } private RoleCollection roles = new RoleCollection(); // Required to be able to properly deal with the Collection object ?? protected override void AddParsedSubObject(object obj) { if (obj is RoleControl) { this.AllowedRoles.Add((RoleControl)obj); return; } } } //////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// [ToolboxData("<{0}:RoleControl runat=server></{0}:RoleControl>")] public class RoleControl : Control { public RoleControl() { } [NotifyParentProperty(true)] [Browsable(true), Description("The allowed role")] public string RoleName { get { return roleType; } set { roleType = value; } } string roleType = ""; } //////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// public class RoleCollection : CollectionBase { public RoleCollection() { } /// <summary> /// Indexer property for the collection that returns and sets an item /// </summary> public RoleControl this[int index] { get { return (RoleControl)this.List[index]; } set { this.List[index] = value; } } public void Add(RoleControl role) { this.List.Add(role); } // NOT USED : public void Insert(int index, RoleControl item) { this.List.Insert(index, item); } public void Remove(RoleControl role) { List.Remove(role); } public bool Contains(RoleControl role) { return this.List.Contains(role); } public int IndexOf(RoleControl role) { return List.IndexOf(role); } public void CopyTo(RoleControl[] array, int index) { List.CopyTo(array, index); } } } |
| | ||||
| ||||
| |
![]() |
| Tags: |
| Outils de la discussion | |
| Modes d'affichage | |
| |