Why using ViewState ?

Sep 19, 2012 at 4:56 PM

Hello all,

I was looking for a captcha and found this one, first i want to thank you for your good job, it's really simple and functional captcha !

Only one thing disturb me, the viewstate :) i think that i'm not the only developper that disable the ViewState and ban it from sites.

In this way, i worked in this captcha control and removed the use of ViewState. I used a hidden input to store the captcha pass hached with MD5. I modified the property GeneratedText like this : (hdnCaptcha is the input hidden)

        private string GeneratedEncreptedText
        {
            get
            {
                return hdnCaptcha.Value;
            }
            set
            {
                // Encrypt the value before storing it in viewstate.
                hdnCaptcha.Value = value;
            }
        }
And the IsValid Property modified like this :


        public bool IsValid
        {
            get
            {
                bool result = GeneratedEncreptedText.ToUpper() == GetMD5Hash(TxtCpatcha.Text.Trim()).ToUpper();
                if (!result)
                    TryNew();
                return result;
            }
        }

thank you and good job !

Jan 14, 2014 at 7:13 AM
Actually, hdnCaptcha has the same meaning with ViewState, isn't it?

As ViewState also stored as hidden field.

But anyway, that's the only way for storing temporary data if ViewState is turned off.
and the idea of Hashing the value is good.