It's been a long while since I've last been here but I've spent the last 2 hours pulling my hair out trying to figure this out and I'm hoping for a bit of help with this one.
I have a question/response check (a human verification check) on my page and it refuses to work... I've written the code such that it generates the question and answer on Page_Load only on the first (non postback) load. I've generated a label which has it's text property pulled from the Question as generated on Page_Load and I'm trying to validate the answer from the generated answer from Page_Load. For some reason it always validates as false even if I put the answer straight from the expected answer into the text box I'm validating from.
Even if I put a line of code in that tells it to fill hAnswer.Text with the value from hAns I still get a failure when validating one against the other. Both are string based variables so this isn't making any kind of sense to me.
Well, as I said, if I insert a line that says hAnswer.Text = hAns it then places the value into hAnswer... following that, the comparison of hAnswer.Text to hAns should match but it still doesn't for some reason.
It is possible that the page variable hAns is losing its value on postBack. You could try storing this in a Session or Viewstate variable instead.
However, as the other guys have suggested, you should place a breakpoint on the line of code for the comparison and check what value each has at that time. Making the assumption that a variable/object has a value because you have set a value at some previous time is not necessarily valid.
You know... I never thought about that... the thing I've been doing is generating (for testing sake) the answer into the hAnswer.Text at the point it's generated. It never occurred to me that during the postback of the page it might clear the variable...
I always kind of figured the point of a locally stored variable was to store info between states lol
Yeah the issue was me being out of practice and completely forgetting that, while a C# program will carry forward variables from state to state, a web-based asp.net script will not carry said variables to the next page state without storing them in some way between states.
Being lazy, I'll just store the "answer" in an invisible field on the page as it's only a "Human Verification" deal and not of any grave security concern.