ASP.net 2.0 Custom Web Control Problem "could not be set on property "

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>
<div class=""StaticSelectBoxScrollDiv"" style=""width:" +
this.Width.ToString() + @";height:" + this.Height.ToString() + @""" >
<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>
{

}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top