好的我已经ViewState["AddressID"]
而且ViewState["AddressID1"]
都存储 AddressID ..现在,如果我想要这样的话: -
if its ViewState["AddressID"]
{
call method 1
}
if its ViewState["AddressID1"]
{
call method 2
}
现在如何检查其ViewState["AddressID"]
或ViewState["AddressID1"]
?
答案 0 :(得分:3)
string addressId = ViewState["AddressID"] as string;
string addressId1 = ViewState["AddressID1"] as string;
if (!string.IsNullOrEmpty(addressId))
{
method1(addressId);
}
else if (!string.IsNullOrEmpty(addressId1))
{
method2(addressId1);
}
答案 1 :(得分:3)
如果ViewState
键没有值,则为null,因此:
if (ViewState["AddressID"] != null)
Method1(ViewState["AddressID"] as string);
else
Method2(ViewState["AddressID1"] as string);