Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > 'True' could not be set on property

Reply
Thread Tools

'True' could not be set on property

 
 
PJ6
Guest
Posts: n/a
 
      10-08-2007
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
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      10-09-2007

"PJ6" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>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
 
 
 
 
=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
Posts: n/a
 
      10-09-2007
Scott M. wrote:
>
> "PJ6" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> 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


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
 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      10-09-2007
"Göran Andersson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> 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
 
Scott M.
Guest
Posts: n/a
 
      10-09-2007
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." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Göran Andersson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> 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

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
<value> could not be set on property <property name> TonyDyer General Computer Support 0 02-14-2012 03:25 PM
Could not find a property named '... ' on the type specified by the DataObjectTypeName property in ObjectDataSource '...' Anabela Silva ASP .Net 0 11-01-2006 07:08 PM
'' Could not be set on Property '' ASP .Net 1 03-03-2005 07:17 AM
ASP.net 2.0 Custom Web Control Problem "could not be set on property " Adam Rogas ASP .Net Building Controls 0 09-14-2004 11:34 PM
'property value' could not be set on property 'propertyname' KJ ASP .Net Web Controls 0 08-26-2003 06:08 PM



Advertisments