Serialization d'un Panel et des ses controles
Bonjour,
J'ai créé un contrôle héritant du CheckBoxList qui me permet d'afficher des Panels en dessous de chaque CheckBox coché.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
public long AttIdARetirer
{
get
{
return ViewState["ActivityTypeCheckBoxList_AttIdARetirer"] as long? ?? -1;
}
set
{
ViewState["ActivityTypeCheckBoxList_AttIdARetirer"] = value;
}
}
public Dictionary<int, List<Panel>> ListPanel = new Dictionary<int, List<Panel>>();
protected override void RenderContents(HtmlTextWriter output)
{
output.Write(Text);
}
protected override void RenderItem(ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
{
base.RenderItem(itemType, repeatIndex, repeatInfo, writer);
//Ajout du panel s'il existe
if (this.Items[repeatIndex].Selected)
{
ListItem li = this.Items[repeatIndex];
int Id;
int.TryParse(li.Value,out Id);
if (ListPanel.ContainsKey(Id))
{
int i = 0;
foreach (Panel p in ListPanel[Id])
{
p.Visible = true;
p.Style.Add("padding-left", "40px");
p.Style.Add("padding-top", "2px");
p.Style.Add("padding-bottom", "2px");
p.Style.Add("padding-right", "2px");
p.Style.Add("margin", "5px");
p.CssClass = i++ % 2 == 0 ? ItemCss : AlternateCss;
p.BorderStyle = BorderStyleCss;
p.BorderWidth = BorderWidthCss;
p.BorderColor = BorderColorCss;
p.RenderControl(writer);
}
}
}
} |
Fonctionnement : Ce contrôle se trouve à la fin d'une liste de Panel.
Sur un choix via un DropDownList d'activité, certains Panels sont affichés (Date, Commentaires,...).
Le CheckBoxList se recharge à chaque action sur le DropDownList et contient les mêmes valeurs que le DropDownList moins l'activité sélectionné dans le DDL.
Lors d'une action sur un CheckBox, je regarde les Panels qui me manque par rapport à ceux affiché via le DDL et j'enregistre ces Panels dans ListPanel du CheckBoxList, ce qui m'affiche correctement tous les Panels dont j'ai besoin entre le DDL et le CBXL.
Le souci vient que si je modifie la valeur d'un contrôle dans un panel du CheckBoxList, la modification n'est pas prise en compte lors du rafraichissement.
J'ai essayé de remplacé
Code:
1 2
|
public Dictionary<int, List<Panel>> ListPanel = new Dictionary<int, List<Panel>>(); |
par
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
public Dictionary<int, List<Panel>> ListPanel
{
get
{
object o = ViewState["ListPanel"];
return o == null ? new Dictionary<int, List<Panel>>() : (Dictionary<int, List<Panel>>)ViewState["ListPanel"];
}
set
{
ViewState["ListPanel"] = value;
}
} |
afin d'avoir une persistance, mais impossible de dé sérialiser le panel.
Donc comment faire ?
Merci de votre aide.