以下例外:
异常:执行命令定义时发生错误 参见
的内部异常
并且没有内部异常。
来自getter的以下代码:
bool IsVerifyingPassword
{
get
{
return (bool?)ViewState["IsDoubleCheckPassword"] ?? false;
}
set { ViewState["IsDoubleCheckPassword"] = value; }
}
我的错在哪里?
答案 0 :(得分:2)
试试:
bool IsVerifyingPassword
{
get
{
bool returnValue = false;
object viewStateValue = ViewState["IsDoubleCheckPassword"];
if (viewStateValue != null)
{
// stay false if not able to retrieve bool from ViewState
bool.TryParse(viewStateValue.ToString(), out returnValue);
}
return returnValue;
}
如果属性真的应该是可以为空的boolean那么:
bool? IsVerifyingPassword
{
get
{
object viewStateValue = ViewState["IsDoubleCheckPassword"];
if (viewStateValue != null)
{
bool returnValue = false;
// stay false if not able to retrieve bool from ViewState
bool.TryParse(viewStateValue.ToString(), out returnValue);
return returnValue;
}else
{
return null;
}
}