in the user control code behind" /> in the user control code behind" /> in the user control code behind"/>

Cannot create an object of type 'System.Nullable` from its string representation 'null' in user control proerty

654 Views Asked by At

I have a user control like this

<uc1:wucSwitchButton3States runat="server" State="true" ID="wucSwitchButton3States" />

in the user control code behind I have declared a nullable property named state

public bool? State { get; set; }

if I set State as true of false it works fine but if I set it as null like this

<uc1:wucSwitchButton3States runat="server" State="null" ID="wucSwitchButton3States" />

I encounter with following error:

Cannot create an object of type 'System.Nullable`... from its string representation 'null' for the 'State' property.

I even tried State="" and State="<%=null%>" but none of them solved the issue, do you have any idea to resolve the problem?

1

There are 1 best solutions below

0
Marco On

based on the CheckBox Code, id did not try it myself but:

bool _state;

[TypeConverter(typeof(NullableBoolConverter))]
public bool? State
{
   get { return _state; }
   set { _state = value; RaisePropertyChanged(); }
}