views:

35

answers:

1

I set ViewState["zzz"] and Session["zzz"] to the same string.

When I compare using == I get false.

When I do ViewState["zzz"].Equals(Session["zzz"]), I get true.

In the debugger, both their values show the same string, and when I do

? ViewState["zzz"] == Session["zzz"]

I get false.

I thought the ViewState StateBag Item defaults to the set value and the Session Item defaults to the value as well?

+3  A: 

Since both ViewState and Session are storing objects, you must cast them to string before comparing, otherwise you'll get a reference comparison instead of the overload string operator == called.

(string) ViewState["zzz"] == (string) Session["zzz"]
Julien Lebosquain
Doh! Of course. I'll accept when it lets me.
Steve