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

Discussion in 'ASP .Net Building Controls' started by Adam Rogas, Sep 15, 2004.

  1. Adam Rogas

    Adam Rogas Guest

    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>
    <tr>
    <td class=""StaticSelectBoxScroll"" onselectstart=""return false;""
    ><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>
    {

    }
    }
    Adam Rogas, Sep 15, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest

    '' Could not be set on Property ''

    Guest, Mar 1, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    3,764
    Steven Cheng[MSFT]
    Mar 3, 2005
  2. PJ6
    Replies:
    4
    Views:
    1,955
    Scott M.
    Oct 9, 2007
  3. Matt Sokol
    Replies:
    2
    Views:
    365
    Theo Tillotson
    Aug 7, 2003
  4. KJ
    Replies:
    0
    Views:
    132
  5. Pete Mahoney

    ASP.Net Server Control (Web Custom Control) Code Update Problem

    Pete Mahoney, Sep 1, 2004, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    175
Loading...

Share This Page