HighTechTalks DotNet Forums  

'True' could not be set on property

ASP.net ASP.net discussions (microsoft.public.dotnet.framework.aspnet)


Discuss 'True' could not be set on property in the ASP.net forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
PJ6
 
Posts: n/a

Default 'True' could not be set on property - 10-08-2007 , 03:22 PM






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(DesignerSerializat ionVisibility.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



Reply With Quote
  #2  
Old   
Scott M.
 
Posts: n/a

Default Re: 'True' could not be set on property - 10-09-2007 , 12:40 AM







"PJ6" <noone (AT) nowhere (DOT) net> wrote

Quote:
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(DesignerSerializat ionVisibility.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



Reply With Quote
  #3  
Old   
Scott M.
 
Posts: n/a

Default Re: 'True' could not be set on property - 10-09-2007 , 10:12 AM



"Göran Andersson" <guffa (AT) guffa (DOT) com> wrote


Quote:
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?




Reply With Quote
  #4  
Old   
Scott M.
 
Posts: n/a

Default Re: 'True' could not be set on property - 10-09-2007 , 10:40 AM



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." <s-mar (AT) nospam (DOT) nospam> wrote

Quote:
"Göran Andersson" <guffa (AT) guffa (DOT) com> wrote in message
news:uquKVbkCIHA.1056 (AT) TK2MSFTNGP03 (DOT) phx.gbl...

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?




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.