• asp.Net的WebValidates验证码控件的使用


    1.在左侧的工具箱中任意选择一个工具,单击鼠标右键选择“添加选项卡”,给控件取个名字,再右键单击该名称,选择“选择项”,在弹出的对话框中,通过 “浏览”按钮,选择准备好的WebValidates.dll文件,单击确定即可将该控件添加到工具箱中了。成功后的效果如图所示:

    关于WebValidates.dll在VS2008和VS2010中遇到的错误问题
     

    2.将该控件拖入到页面中,就会出现错误,关于WebValidates.dll在VS2008和VS2010中遇到的错误问题但没有关系,你只要去正常使用就行了。

    在该页面的Page_Load事件中写如 下代码:(snCode为该验证码控件的名字)

     

    view plaincopy to clipboardprint?
     protected void Page_Load(object sender, EventArgs e)  
        {  
            if(!IsPostBack)  
            {  
                //加载时生成验证码  
                snCode.Create();  
            }  
        }  
        /// <summary>  
        /// 判断验证码是否正确  
        /// </summary>  
        /// <returns></returns>  
        protected bool CheckCode()  
        {  
            if (snCode.CheckSN(this.txtNum.Text.Trim()))  
            {  
                return true;  
            }  
            else 
            {  
                snCode.Create();  
                return false;  
            }  
        }  
        //提交按钮单击事件  
        protected void btnAdd_Click(object sender, EventArgs e)  
        {  
                if (!CheckCode())  
                {  
                    this.ltMain.Text = "<font size='2' color='red'>验证码不正确</font>";  
                    return;  
                }  
                StuInfo stu = new StuInfo();  
                stu.StuName = txtStuName.Text.Trim();  
                stu.Age = int.Parse(txtAge.Text.Trim());  
                stu.Sex = ddlSex.Text.Trim();  
                stu.Address = ftbAddress.Text;  
                bool bl = StuInfoManager.AddStuInfo(stu);  
                if (bl)  
                {  
                    Response.Write("<mce:script type="text/javascript"><!--  
    alert('恭喜,注册成功!');  
    // --></mce:script>");  
                }  
        } 

  • 相关阅读:
    关于Eclipse开发插件(三)
    关于Eclipse插件开发(一)
    关于Eclipse中开发插件(二)
    Android-ImageView的属性android:scaleType作用
    bigautocomplete实现联想输入,自动补全
    Sqlite-Sqlite3中的数据类型
    C#/Sqlite-单机Window 程序 sqlite 数据库实现
    C#/Sqlite-SQLite PetaPoco django 打造桌面程序
    桌面轻量级数据库的选择:Access、SQLite、自己编写?
    如何开始创业
  • 原文地址:https://www.cnblogs.com/Jhon-xu/p/4530397.html
Copyright © 2020-2023  润新知