473,545 Members | 1,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to persist an arraylist property of controls in a custom control.

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;
}
}

}

Feb 22 '06 #1
0 3240

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2480
by: Pierson C | last post by:
A quick easy one! I have a custom user control that has an ArrayList property. I create an instance of the user control, assign all of the properties, but when I add the control to the page, my ArrayList variable has gone out of scope (all int and string properties still exist). It must be where an ArrayList is treated like an Object,...
1
1057
by: andrew | last post by:
I am trying to save data to disk. I intend using the Binary Formatter Class. I have an arraylist populated with custom class objects. Several of these custom classes contain button controls as properties. i.e Public Class MyCustomClass
0
1247
by: James | last post by:
I have a composite custom control which is constructed of several other controls, such as command buttons, a listview etc. I have several controls which border the boundary of the container and have their anchor properties set accordingly, for example, ensuring a button stays on the right border when the control is resized. Now in the control's...
20
5949
by: Dennis | last post by:
I use the following code for a strongly typed arraylist and it works great. However, I was wondering if this is the proper way to do it. I realize that if I want to implement sorting of the arraylist then I have to handle this with a sort method that uses comparer. I can reference the properties of the Arraylist directly such as dim...
18
4712
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the class where only the "searched" property has a value. I expected to get the index into the arraylist where I could then get the entire class...
0
880
by: Umut Tezduyar | last post by:
I have build a sample control but the designer doesn't communicate with it to parse the childen property. Please if you are an control developer, spend your 10 minutes to solve my problem. I have read so many articles and books to solve it but i couldn't. Here is the code sample: ---------- Asp Page ---------------- <form id="Form1"...
0
998
by: Umut Tezduyar | last post by:
I have build a sample control but the designer doesn't communicate it to parse the childen. Please if you are an control developer, spend your 10 minutes to solve my problem. The main problem is, whenever i made a change in the sub object (Tab) it doesn't persist the changes to the asp.net page. Here is the code sample: ---------- Asp...
1
2984
by: suki | last post by:
How can i set the data binding property of an label to a field of a dataset (defined in a class in my project) ? In this data field, there are many entries and i want to have as much labels as entries... Does the label duplicate automatically? How can i do that?
1
8341
by: Don | last post by:
I'm getting the following exception displayed in the task list at design time for my project: "Code generation for property 'Controls' failed. Error was: 'Object reference not set to an instance of an object.'" I've traced the problem to a custom control I created that inherits from Inherits System.Windows.Forms.TextBox. In this custom...
0
7464
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7805
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7413
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4943
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3449
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3440
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1874
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.