开发者

about viewstate

开发者 https://www.devze.com 2023-01-26 11:47 出处:网络
Ok I have got ViewState[\"AddressID\"] a开发者_Python百科nd this ViewState[\"AddressID1\"] both storing AddressIDs..Now if I want something like :-

Ok I have got ViewState["AddressID"] a开发者_Python百科nd this ViewState["AddressID1"] both storing AddressIDs..Now if I want something like :-

if its ViewState["AddressID"]    
{
   call method 1
}

if its ViewState["AddressID1"]    
{
   call method 2
}

now how do I check if its ViewState["AddressID"] or ViewState["AddressID1"]?


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);
}


If a ViewState key doesn't have a value it is null, so:

if (ViewState["AddressID"] != null) 
  Method1(ViewState["AddressID"] as string);
else 
  Method2(ViewState["AddressID1"] as string);
0

精彩评论

暂无评论...
验证码 换一张
取 消