ASP.NET 验证码案例

来源:互联网 发布:崔走召的网络电影 编辑:程序博客网 时间:2024/06/10 22:48


分享一下验证码的小案例



 protected void Page_Load(object sender, EventArgs e)
        {
            //是否是第一次加载
            if(!Page.IsPostBack)
            {
                //加载验证码
                this.snCode.Create();
            }
        }



        //该方法用来判断当前验证码是否正确
        public bool IsBool()
        {
            if(snCode.CheckSN(this.txtCode.Text.Trim()))    //在txtCode文本框中严重  当前输入的验证码是否正确
            {
                return true;
            }
            else
            {
                //更新验证码
                this.snCode.Create();
                return false;
            }
        }
        //提交事件
        protected void btnsubmit_Click(object sender, EventArgs e)
        {
            if (IsBool())
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "提示", "alert('验证通过')", true);
            }
            else
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "提示", "alert('验证失败')", true);
            }
        }

0 0
原创粉丝点击