A
Adam Rogas
I am having a problem with a property that is a collection. This is
only happening in design time but If I add the control to a page and
then use the properties window collection editor to add items to the
Buttons property, my collection, it renders in design time correctly;
however if after I have done that I switch to code view and then
switch back to design view it renders the control as an error and has
a tool tip of "'ListSelectBox' could not be set on property 'Buttons'"
I have included the code below, and I have tried every thing I can get
my hands on to remedy the problem. Any assistance would be much
appriciated.
#region Using directives
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
#endregion
namespace Controls
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:ListSelectBox
runat=server></{0}:ListSelectBox>")]
[ParseChildren(true)]
[PersistChildren(false)]
public class ListSelectBox : WebControl
{
// protected override void AddParsedSubObject(object obj)
// {
// if (obj is ListSelectBoxButton)
// {
// this.m_buttons.Add((ListSelectBoxButton)obj);
// return;
// }
// }
private string m_header;
private ButtonsCollection m_buttons = new ButtonsCollection();
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
public string Header
{
get
{
return m_header;
}
set
{
m_header = value;
}
}
[Category("Appearance")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[NotifyParentProperty(true)]
public ButtonsCollection Buttons
{
get
{
return m_buttons;
}
set
{
m_buttons = value;
}
}
protected override void Render(HtmlTextWriter output)
{
output.Write(
@"<table cellpadding=0 cellspacing=0 border=0>
<tr>
<td class=""StaticSelectBoxHeader"">Website Sections<td>
</tr>
<tr>
<td class=""StaticSelectBoxButtons"" align=""right"">");
foreach (ListSelectBoxButton Button in m_buttons)
{
Button.RenderControl(output);
}
output.Write(@"<td>
</tr>
<table width=100% cellpadding=0 cellspacing=0 border=0>");
output.Write(@" <tr><td
class=""StaticSelectBoxItem"" onclick=""alert('Item Selected')"">This
is a test</td></tr>");
output.Write(@" </table>
</div><td>
</tr>
</table>");
}
}
[ToolboxData("<{0}:ListSelectBoxButton runat=server />")]
[ParseChildren(false)]
[PersistChildren(false)]
public class ListSelectBoxButton :
System.Web.UI.WebControls.Button
{
}
public class ButtonsCollection :
System.Collections.Generic.Collection<ListSelectBoxButton>
{
}
}
only happening in design time but If I add the control to a page and
then use the properties window collection editor to add items to the
Buttons property, my collection, it renders in design time correctly;
however if after I have done that I switch to code view and then
switch back to design view it renders the control as an error and has
a tool tip of "'ListSelectBox' could not be set on property 'Buttons'"
I have included the code below, and I have tried every thing I can get
my hands on to remedy the problem. Any assistance would be much
appriciated.
#region Using directives
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
#endregion
namespace Controls
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:ListSelectBox
runat=server></{0}:ListSelectBox>")]
[ParseChildren(true)]
[PersistChildren(false)]
public class ListSelectBox : WebControl
{
// protected override void AddParsedSubObject(object obj)
// {
// if (obj is ListSelectBoxButton)
// {
// this.m_buttons.Add((ListSelectBoxButton)obj);
// return;
// }
// }
private string m_header;
private ButtonsCollection m_buttons = new ButtonsCollection();
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
public string Header
{
get
{
return m_header;
}
set
{
m_header = value;
}
}
[Category("Appearance")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[NotifyParentProperty(true)]
public ButtonsCollection Buttons
{
get
{
return m_buttons;
}
set
{
m_buttons = value;
}
}
protected override void Render(HtmlTextWriter output)
{
output.Write(
@"<table cellpadding=0 cellspacing=0 border=0>
<tr>
<td class=""StaticSelectBoxHeader"">Website Sections<td>
</tr>
<tr>
<td class=""StaticSelectBoxButtons"" align=""right"">");
foreach (ListSelectBoxButton Button in m_buttons)
{
Button.RenderControl(output);
}
output.Write(@"<td>
</tr>
this.Width.ToString() + @";height:" + this.Height.ToString() + @""" ><div class=""StaticSelectBoxScrollDiv"" style=""width:" +
<table width=100% cellpadding=0 cellspacing=0 border=0>");
output.Write(@" <tr><td
class=""StaticSelectBoxItem"" onclick=""alert('Item Selected')"">This
is a test</td></tr>");
output.Write(@" </table>
</div><td>
</tr>
</table>");
}
}
[ToolboxData("<{0}:ListSelectBoxButton runat=server />")]
[ParseChildren(false)]
[PersistChildren(false)]
public class ListSelectBoxButton :
System.Web.UI.WebControls.Button
{
}
public class ButtonsCollection :
System.Collections.Generic.Collection<ListSelectBoxButton>
{
}
}