Thank you. What would it take to get the control to "read" these values
after the GUI page has been saved and closed then reopened again? It seems
that if I do this the control reverts to "Error Creating Control". My guess
is that it is not reading these values but I am not absolutly certain.
Below is my controls code (please excuse my ignorance, like I said I am very
new to this!):
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.Design;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.IO;
using System.Text;
using System.Drawing.Design;
//using System.
[
assembly: TagPrefix("ControlGroup","ControlGroup")
]
namespace ControlGroup
{
/// <summary>
/// Summary description for WebCustomControl1.
/// </summary>
///
[DefaultProperty("Text"),
ToolboxData("<{0}:ControlGroupControl
runat=server></{0}:ControlGroupControl>"),
SerializableAttribute()]
public class ControlGroupControl : System.Web.UI.WebControls.WebControl,
INamingContainer
{
#region Private Variables
private string text="";
private ControlGroupItemCollection items = new ControlGroupItemCollection();
private ControlGroupItemCollection allItems = new
ControlGroupItemCollection();
private ListBox lbItems = new ListBox();
private Label lblTitleID = new Label();
private TextBox txtInfo = new TextBox();
#endregion
#region Constructors and Initializers
public ControlGroupControl()
{
try
{
this.Visible=true;
txtInfo.Height=300;
//this.Height=100;
//this.Width=100;
lbItems.BorderStyle=BorderStyle.None;
lbItems.BorderWidth=0;
lbItems.Width=300;
txtInfo.Width=300;
txtInfo.TextMode=TextBoxMode.MultiLine;
txtInfo.Text += "CONSTRUCTED!\n";
}
catch (Exception ex)
{
items=null;
allItems=null;
text="Error! - " + ex.ToString();
}
}
protected override void OnInit(EventArgs e)
{
if (AllItems.Count != Page.Controls.Count-1)
{
txtInfo.Text += "INITIALIZED & RESET!\n";
fillAllItems();
}
base.OnInit (e);
}
protected override void OnLoad(EventArgs e)
{
txtInfo.Text += "LOADED!\n";
base.OnLoad (e);
}
protected override void OnPreRender(EventArgs e)
{
txtInfo.Text += "PRE-RENDER!\n";
base.OnPreRender (e);
}
#endregion
#region Void Methods
private void FillListBox()
{
//Start by clearing the list
lbItems.Items.Clear();
//If the items collection has not been instantiated then
//Do not attempt to iterate through it.
if (items.Count>0)
{
//for (int i=0; i< items.Count; i++)
foreach(ControlGroupItem cntl in items)
{
lbItems.Items.Add(cntl.ControlID.ToString());
}
}
else
{
//Writes "No Controls
lbItems.Items.Add("No Controls");
}
}
private void fillAllItems()
{
try
{
int c = Page.Controls.Count;
int tmpID=0;
ControlGroupItem tempControl = new ControlGroupItem();
allItems.Clear();
for(int i=0; i < c; i++)
{
//txtInfo.Text = txtInfo.Text + Page.Controls.ID.ToString() + "\n";
tempControl = new ControlGroupItem();
// set the control structure properties of the control
tempControl.ControlID = Page.Controls.ID.ToString();
tempControl.ControlType = Page.Controls.GetType();
//tempControl.BoundProperty=
// add the control structure to the collection
tmpID=this.allItems.Add(tempControl);
txtInfo.Text +="CONTROL " + this.allItems[tmpID].ControlID.ToString() + " ["
+ allItems.Count.ToString() + "]\n";
}
this.Text="WORKED!";
}
catch (Exception ex)
{
System.Diagnostics.Debug.Write(ex.ToString());
this.Text=ex.ToString();
}
}
#endregion
#region Properties
[
Bindable(true),
Category("Data"),
]
public string Text
{
get
{
return text;
}
set
{
text=value;
}
}
/// <summary>
/// Items = The group of referenced controls
/// </summary>
[Category("Misc"),
PersistenceMode(PersistenceMode.InnerProperty),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true),
EditorAttribute(typeof(ControlGroupEditor), typeof(UITypeEditor))
]
public ControlGroupItemCollection Items
{
get
{
return items;
}
}
[BrowsableAttribute (false)]
public ControlGroupItemCollection AllItems
{
get
{
return allItems;
}
set
{
allItems = value;
}
}
#endregion
#region Rendering
protected override StateBag ViewState
{
get
{
return base.ViewState;
}
}
protected override object SaveViewState()
{
return base.SaveViewState ();
}
protected override void LoadViewState(object savedState)
{
base.LoadViewState (savedState);
}
protected override void RenderContents(HtmlTextWriter writer)
{
//Render(writer);
base.RenderContents (writer);
}
protected override void RenderChildren(HtmlTextWriter writer)
{
FillListBox();
lblTitleID.Text=this.ID.ToString();
// Render
lblTitleID.RenderControl(writer);
writer.Write("<BR>");
lbItems.RenderControl(writer);
writer.Write("<BR>");
txtInfo.RenderControl(writer);
}
#endregion
}
}