'True' could not be set on property

Discussion in 'ASP .Net' started by PJ6, Oct 8, 2007.

  1. PJ6

    PJ6 Guest

    I get this design-time error (below) when setting thus property in my
    inherited web control to 'True'. I've debugged the code running at
    design-time to double check to see that no exception was being thrown. While
    there are other people that have run into this exception, what I've found so
    far hasn't been helpful.

    What is the proper way to declare custom Boolean properties that need to be
    persisted in attributes through the Web Forms designer?

    Paul

    There was an error rendering the control.
    'True' could not be set on property 'ShowEmptySelection'.

    <DefaultValue(False), _
    DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
    _
    PersistenceMode(PersistenceMode.Attribute), _
    Bindable(True), Category("Appearance")> _
    Public Overridable Property ShowEmptySelection() As Boolean
    Get
    Dim ret As Boolean = False
    Dim o As Object = Me.ViewState("ShowEmptySelection")
    If Not o Is Nothing Then
    ret = CBool(o)
    End If
    Return ret
    End Get
    Set(ByVal value As Boolean)
    Me.ViewState("ShowEmptySelection") = value
    End Set
    End Property
    PJ6, Oct 8, 2007
    #1
    1. Advertising

  2. PJ6

    Scott M. Guest

    "PJ6" <> wrote in message
    news:%...
    >I get this design-time error (below) when setting thus property in my
    >inherited web control to 'True'. I've debugged the code running at
    >design-time to double check to see that no exception was being thrown.
    >While there are other people that have run into this exception, what I've
    >found so far hasn't been helpful.
    >
    > What is the proper way to declare custom Boolean properties that need to
    > be persisted in attributes through the Web Forms designer?
    >
    > Paul
    >
    > There was an error rendering the control.
    > 'True' could not be set on property 'ShowEmptySelection'.
    >
    > <DefaultValue(False), _
    >
    > DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
    > _
    > PersistenceMode(PersistenceMode.Attribute), _
    > Bindable(True), Category("Appearance")> _
    > Public Overridable Property ShowEmptySelection() As Boolean
    > Get
    > Dim ret As Boolean = False
    > Dim o As Object = Me.ViewState("ShowEmptySelection")
    > If Not o Is Nothing Then
    > ret = CBool(o)
    > End If
    > Return ret
    > End Get
    > Set(ByVal value As Boolean)
    > Me.ViewState("ShowEmptySelection") = value
    > End Set
    > End Property
    >
    >


    I'm not sure, but if you don't mind, may I suggest you change your Get code?
    What you have there is very unneccessary.

    Public Overridable Property ShowEmptySelection() As Boolean
    Get
    If Me.ViewState("ShowEmptySelection") IsNot Nothing Then Return
    True
    Return False
    End Get
    Set(ByVal value As Boolean)
    Me.ViewState("ShowEmptySelection") = value
    End Set
    End Property
    Scott M., Oct 9, 2007
    #2
    1. Advertising

  3. Scott M. wrote:
    >
    > "PJ6" <> wrote in message
    > news:%...
    >> I get this design-time error (below) when setting thus property in my
    >> inherited web control to 'True'. I've debugged the code running at
    >> design-time to double check to see that no exception was being thrown.
    >> While there are other people that have run into this exception, what
    >> I've found so far hasn't been helpful.
    >>
    >> What is the proper way to declare custom Boolean properties that need
    >> to be persisted in attributes through the Web Forms designer?
    >>
    >> Paul
    >>
    >> There was an error rendering the control.
    >> 'True' could not be set on property 'ShowEmptySelection'.
    >>
    >> <DefaultValue(False), _
    >>
    >> DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
    >> _
    >> PersistenceMode(PersistenceMode.Attribute), _
    >> Bindable(True), Category("Appearance")> _
    >> Public Overridable Property ShowEmptySelection() As Boolean
    >> Get
    >> Dim ret As Boolean = False
    >> Dim o As Object = Me.ViewState("ShowEmptySelection")
    >> If Not o Is Nothing Then
    >> ret = CBool(o)
    >> End If
    >> Return ret
    >> End Get
    >> Set(ByVal value As Boolean)
    >> Me.ViewState("ShowEmptySelection") = value
    >> End Set
    >> End Property
    >>
    >>

    >
    > I'm not sure, but if you don't mind, may I suggest you change your Get
    > code? What you have there is very unneccessary.
    >
    > Public Overridable Property ShowEmptySelection() As Boolean
    > Get
    > If Me.ViewState("ShowEmptySelection") IsNot Nothing Then
    > Return True
    > Return False
    > End Get
    > Set(ByVal value As Boolean)
    > Me.ViewState("ShowEmptySelection") = value
    > End Set
    > End Property


    But that will make the property always return true if there is a value
    in view state, regardless of the actual value.

    --
    Göran Andersson
    _____
    http://www.guffa.com
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, Oct 9, 2007
    #3
  4. PJ6

    Scott M. Guest

    "Göran Andersson" <> wrote in message
    news:...

    > But that will make the property always return true if there is a value in
    > view state, regardless of the actual value.


    It seems like that's what the OP wants here since all he was doing in his
    original code was casting the value to a Boolean. Wouldn't any value cause
    the cast to result in True, but no value would cause False?
    Scott M., Oct 9, 2007
    #4
  5. PJ6

    Scott M. Guest

    To follow up...

    If the OP wanted the "value" of the ViewState item cast as a boolean, should
    he not have casted the ViewState item to a string and cast that, rather than
    cast the ViewState "item" to an object?



    "Scott M." <> wrote in message
    news:...
    > "Göran Andersson" <> wrote in message
    > news:...
    >
    >> But that will make the property always return true if there is a value in
    >> view state, regardless of the actual value.

    >
    > It seems like that's what the OP wants here since all he was doing in his
    > original code was casting the value to a Boolean. Wouldn't any value
    > cause the cast to result in True, but no value would cause False?
    >
    Scott M., Oct 9, 2007
    #5
    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,765
    Steven Cheng[MSFT]
    Mar 3, 2005
  2. Anabela Silva
    Replies:
    0
    Views:
    1,195
    Anabela Silva
    Nov 1, 2006
  3. bdb112
    Replies:
    45
    Views:
    1,318
    jazbees
    Apr 29, 2009
  4. Adam Rogas
    Replies:
    0
    Views:
    203
    Adam Rogas
    Sep 15, 2004
  5. KJ
    Replies:
    0
    Views:
    134
Loading...

Share This Page