I have included below virtually all the code to a control I'm trying to
build. My issue is that an array list property in my control does not get
persisted properly to the aspx page code in design time. If I type the code
in the aspx manually it does get parsed correctly though.
This is an example of the aspx code that gets parsed correctly. For some
reason, if I changed update the Tab property of the control through the GUI
at design time, the changes are not persisted in the aspx page. As well,
if I change one of the other properties of the TabList control itself, all
the inner html of the control is removed from the aspx page. My control
consists of an arraylist property called tabs which contains instances of
TabListItem objects. The TabListItem object can contain various web
controls as child controls in it's Controls property. Any help here would
be greatly appreciated. Thanks.
<myasp:TabLis t id="TabList2g" runat="server" Width="328px" Height="48px"
BorderWidth="4p x" CssClass="test2 3">
<myasp:TabListI tem>
<asp:Button ID="test1" Text="Tab 1" Font-Bold="True"></asp:Button>
</myasp:TabListIt em>
<myasp:TabListI tem>
<asp:Button ID="test2" Text="Tab 2"></asp:Button>
</myasp:TabListIt em>
<myasp:TabListI tem>
<asp:Button ID="test3" Text="Tab 3 part1"></asp:Button>
<asp:Button ID="test4" Text="Tab 3 part2"></asp:Button>
</myasp:TabListIt em>
<myasp:TabListI tem>
<asp:Button ID="test5" Text="Tab 4 part1"></asp:Button>
<asp:Button ID="test6" Text="Tab 4 part2"></asp:Button>
</myasp:TabListIt em>
</myasp:TabList>
using System;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Componen tModel;
using System.Collecti ons;
using System.Security ;
[assembly: System.Web.UI.T agPrefix("MyDot Net.Web.UI.WebC ontrols", "myasp")]
namespace MyDotNet.Web.UI .WebControls
{
public class TabListBuilder : ControlBuilder
{
[System.Security .Permissions.Pe rmissionSet(Sys tem.Security.Pe rmissions.Secur ityAction.Deman d,
Name="FullTrust ")]
public override Type GetChildControl Type(string tagName,
System.Collecti ons.IDictionary attribs)
{
if (tagName.ToLowe r().EndsWith("t ablistitem"))
{
return typeof(TabListI tem);
}
return null;
}
[System.Security .Permissions.Pe rmissionSet(Sys tem.Security.Pe rmissions.Secur ityAction.Deman d,
Name="FullTrust ")]
public override void AppendLiteralSt ring(string s)
{
//Ignore
}
}
public class TabListItemBuil der : ControlBuilder
{
[System.Security .Permissions.Pe rmissionSet(Sys tem.Security.Pe rmissions.Secur ityAction.Deman d,
Name="FullTrust ")]
public override Type GetChildControl Type(string tagName,
System.Collecti ons.IDictionary attribs)
{
if (tagName.ToLowe r().EndsWith("l abel"))
{
return typeof(Label);
}
else if (tagName.ToLowe r().EndsWith("b utton"))
{
return typeof(Button);
}
else if (tagName.ToLowe r().EndsWith("l inkbutton"))
{
return typeof(LinkButt on);
}
else if (tagName.ToLowe r().EndsWith("i magebutton"))
{
return typeof(ImageBut ton);
}
else if (tagName.ToLowe r().EndsWith("h yperlink"))
{
return typeof(HyperLin k);
}
else if (tagName.ToLowe r().EndsWith("i mage"))
{
return typeof(Image);
}
else if (tagName.ToLowe r().EndsWith("l iteral"))
{
return typeof(Literal) ;
}
return null;
}
[System.Security .Permissions.Pe rmissionSet(Sys tem.Security.Pe rmissions.Secur ityAction.Deman d,
Name="FullTrust ")]
public override void AppendLiteralSt ring(string s)
{
//Ignore
}
}
[//ControlBuilderA ttribute(typeof (TabListBuilder )), /*TabListBuilder will
parse child controls */
ParseChildren(t rue, "Tabs"),/*true - child elements are parsed as
properties, not controls*/
PersistChildren (false) /*false - persist child controls only as child
elements*/]
public class TabList : WebControl, INamingContaine r
{
const string strCATEGORY_TAB S = "Tabs";
const string strCATEGORY_APP EARANCE = "Appearance ";
private Table pTable_m;
private ArrayList pTabs_m = new ArrayList();
private int iSelectedTabInd ex_m = -1;
[EditorAttribute (typeof(TabList ItemArrayListEd itor),
typeof(System.D rawing.Design.U ITypeEditor)), /*Custom editor for the
TabListItem objects in the ArrayList */
PersistenceMode (PersistenceMod e.InnerProperty ),
MergablePropert y(false),
DesignerSeriali zationVisibilit yAttribute(Desi gnerSerializati onVisibility.Co ntent)]
public ArrayList Tabs
{
get
{
return pTabs_m;
}
}
[Bindable(true),
Category(strCAT EGORY_TABS),
DefaultValue(-1)]
public int SelectedTabInde x
{
get
{
return iSelectedTabInd ex_m;
}
set
{
iSelectedTabInd ex_m = value;
}
}
// Called at runtime when a child object is added to the collection.
[System.Security .Permissions.Pe rmissionSet(Sys tem.Security.Pe rmissions.Secur ityAction.Deman d,
Name="FullTrust ")]
protected override void AddParsedSubObj ect(object obj)
{
TabListItem pItem = obj as TabListItem;
if (pItem != null)
{
pTabs_m.Add(pIt em);
}
}
protected override void CreateChildCont rols()
{
pTable_m = new Table();
pTable_m.Rows.A dd(new TableRow());
foreach(TabList Item pItem in pTabs_m)
{
TableCell pCell = new TableCell();
pTable_m.Rows[0].Cells.Add(pCel l);
pCell.Controls. Add(pItem);
}
Controls.Clear( );
Controls.Add(pT able_m);
}
}
/// <summary>
/// Represents 1 tab in the TabList control
/// </summary>
[ControlBuilderA ttribute(typeof (TabListItemBui lder)),/*TabListItemBui lder
will parse child controls */
ToolboxItem(fal se),/*Do not show this control in the toolbox*/
ParseChildren(f alse)/*false - child elements are parsed as controls, not
properties*/,
PersistChildren (true) /*false - persist child controls only as child
elements*/]
public class TabListItem : WebControl, INamingContaine r
{
private ArrayList pTabControls_m = new ArrayList();
public TabListItem()
{
}
// Called at runtime when a child object is added to the collection.
[System.Security .Permissions.Pe rmissionSet(Sys tem.Security.Pe rmissions.Secur ityAction.Deman d,
Name="FullTrust ")]
protected override void AddParsedSubObj ect(object obj)
{
Control pItem = obj as Control;
if (pItem != null)
{
Controls.Add(pI tem);
}
}
}
public class TabListItemArra yListEditor :
System.Drawing. Design.UITypeEd itor
{
public TabListItemArra yListEditor() : base()
{
}
public override object
EditValue(Syste m.ComponentMode l.ITypeDescript orContext context,
IServiceProvide r provider, object value)
{
try
{
IWindowsFormsEd itorService pSvc = null;
if (context != null &&
provider != null &&
context.Instanc e != null)
{
pSvc =
(IWindowsFormsE ditorService)pr ovider.GetServi ce(typeof(IWind owsFormsEditorS ervice));
}
if (pSvc != null)
{
frmTabEditor pForm = new frmTabEditor();
ArrayList pCollection = (ArrayList)valu e;
pForm.Tabs = pCollection;
if (pForm.ShowDial og() == DialogResult.OK )
{
value = pCollection;
}
}
}
catch (Exception ex)
{
MessageBox.Show (ex.ToString()) ;
}
return value;
}
// Indicates whether the UITypeEditor provides a form-based (modal)
dialog,
// drop down dialog, or no UI outside of the properties window.
public override System.Drawing. Design.UITypeEd itorEditStyle
GetEditStyle(Sy stem.ComponentM odel.ITypeDescr iptorContext context)
{
return UITypeEditorEdi tStyle.Modal;
}
}
}