Possible Duplicate:
Is there a global variable (across web pages) I can use in C# WebMatrix, that actually works?
I have a rather odd (to me) problem. I have tested and tried many things and traced the problem down to one simple fact.
When I try to compare an AppState["uniqueName"] to a string value, it always evaluates to false. Here are a couple of snippets so you can see what I have:
On the first page:
AppState["gAdmitsMembership"] = AdmitsMembership;
On the second page:
if(AppState["gAdmitsMembership"]=="true"){checkBoxes[0]="checked='checked'";}else{checkBoxes[0]="";}
As you can probably tell the point is to keep a checkbox checked after submitting a form (and subsequently bringing the data back up in another form for possible editing)
Now, as I stated, I have tested many things and this is what I have done.
I plotted the value of AppState["gAdmitsMembership"] directly to a text input field (in the second page), in order to see what the actual value being tested was. It was indeed "true", however it still always equates to false (which I determined with another test by manipulating what happens with the "else".
Why is this failing the if condition?
It is important to note that nowhere in the code is this value "true" a boolean value. It is always the string "true". I have to do it this way because when I try:
if(AppState["gAdmitsMembership"]==true){checkBoxes[0]="checked='checked'";}else{checkBoxes[0]="";}
(same thing only with boolean true)
I get an error that says '== cannot be compared to objects or boolean' or something to that effect.
For this reason the compared string value must remain as "true" so that when it is added to the database it will be converted to the database as the necessary boolean value, true.
Anyway, any help that gets me through this will be quickly accepted and definitely appreciated. Thanks!