Professional Web Applications Themes

Collection Property in web custom control - ASP.NET

Hi all, I'm building a custom control. I would like that on the control you can set some 'rights' For that I have an enum: public enum GroupRights { Group0 = 0, Group1 = 1, Group2 = 2, Group3 = 3, Group4 = 4, Group5 = 5, } In design time I want to set these right (can be multiple rights at the same time) So I put them in a generic list: [Category("Rights")] [DefaultValue("")] [Localizable(true)] [Bindable(true)] public List<GroupRights> ControlRights { get { List<GroupRights> temp = (List<GroupRights>)ViewState["ControlRights"]; return ((object)temp == null) ? new List<GroupRights>() : temp; } set { ViewState["ControlRights"] ...

  1. #1

    Default Collection Property in web custom control

    Hi all,

    I'm building a custom control. I would like that on the control you can set
    some 'rights'
    For that I have an enum:
    public enum GroupRights

    {
    Group0 = 0,
    Group1 = 1,
    Group2 = 2,
    Group3 = 3,
    Group4 = 4,
    Group5 = 5,
    }

    In design time I want to set these right (can be multiple rights at the same
    time)
    So I put them in a generic list:

    [Category("Rights")]
    [DefaultValue("")]
    [Localizable(true)]
    [Bindable(true)]
    public List<GroupRights> ControlRights
    {
    get
    {
    List<GroupRights> temp = (List<GroupRights>)ViewState["ControlRights"];
    return ((object)temp == null) ? new List<GroupRights>() : temp;
    }

    set
    {
    ViewState["ControlRights"] = value;
    }}

    In desgin time I get the controls window with the GrouRights enum to choose
    from.
    But when I add one right in the collection window I get the message:

    Cannot create an object of type
    'System.Collections.Generic.List`1[[GroupRights, MaxControls,
    Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' from its string
    representation '(Collection)' for the 'ControlRights' property.

    Also the property can not be read out during runtime.

    What am I doing wrong or forgetting?

    tia,

    Class



    Class Guest

  2. #2

    Default Re: Collection Property in web custom control

    Your class must be serializible. Or use Session instead of ViewState.

    Sincerely yours,
    Michael B. Tkachev.
    [email]m_tkachevhotmail.com[/email]

    "Class" <NoSpamClass> wrote in message
    news:eOfpVChOHHA.2140TK2MSFTNGP03.phx.gbl...
    > Hi all,
    >
    > I'm building a custom control. I would like that on the control you can
    > set some 'rights'
    > For that I have an enum:
    > public enum GroupRights
    >
    > {
    > Group0 = 0,
    > Group1 = 1,
    > Group2 = 2,
    > Group3 = 3,
    > Group4 = 4,
    > Group5 = 5,
    > }
    >
    > In design time I want to set these right (can be multiple rights at the
    > same time)
    > So I put them in a generic list:
    >
    > [Category("Rights")]
    > [DefaultValue("")]
    > [Localizable(true)]
    > [Bindable(true)]
    > public List<GroupRights> ControlRights
    > {
    > get
    > {
    > List<GroupRights> temp = (List<GroupRights>)ViewState["ControlRights"];
    > return ((object)temp == null) ? new List<GroupRights>() : temp;
    > }
    >
    > set
    > {
    > ViewState["ControlRights"] = value;
    > }}
    >
    > In desgin time I get the controls window with the GrouRights enum to
    > choose from.
    > But when I add one right in the collection window I get the message:
    >
    > Cannot create an object of type
    > 'System.Collections.Generic.List`1[[GroupRights, MaxControls,
    > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' from its string
    > representation '(Collection)' for the 'ControlRights' property.
    >
    > Also the property can not be read out during runtime.
    >
    > What am I doing wrong or forgetting?
    >
    > tia,
    >
    > Class
    >
    >
    >

    Michael Tkachev Guest

Similar Threads

  1. Custom Control - Collection Property
    By Synced in forum ASP.NET
    Replies: 1
    Last Post: January 17th, 03:33 AM
  2. Nested Collection property in a custom control
    By apratimg@gmail.com in forum ASP.NET Building Controls
    Replies: 1
    Last Post: September 30th, 01:57 PM
  3. Collection Property of Another Custom Server Control
    By Sean in forum ASP.NET Building Controls
    Replies: 1
    Last Post: January 12th, 06:38 PM
  4. Help with using a custom collection as a property for a TextBox derrived control.
    By Chris Crowe [MVP] in forum ASP.NET Building Controls
    Replies: 3
    Last Post: August 24th, 02:54 PM
  5. Custom Control nad Collection property
    By Brian Bugge in forum ASP.NET Building Controls
    Replies: 0
    Last Post: July 2nd, 02:09 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139