如何用C#实现验证码

来源:百度知道 编辑:UC知道 时间:2024/06/15 03:32:34
private void btnlogin_Click(object sender, System.EventArgs e)
{

//BusinessTeacher TeacherloginUsr=new BusinessTeacher();
String strLoginID= username.Text .Trim ();
String strPassword =password.Text .Trim ();
string strReason;

switch (userTypeList.SelectedItem.Text)
{
case "学生":
BusinessObject.Student stuLogin=new BYSJManageSystem.BYSJBLLayer.BusinessObject.Student();
String[] strLoginflag =stuLogin.StudentLogin(strLoginID,strPassword);
if(strLoginflag[1].Trim()!="success")
{

strReason=strLoginflag[1] + ",并请检查登陆的类型";
Response.Write("<script language=javascript>");
Response.Write("window.alert('");
Response.Write(strReason );
Response.Write("');");
Response.Write("</script>");
}<

private void btnlogin_Click(object sender, System.EventArgs e)

{
.........
.........
.........
//以上是你的代码

HttpCookie cookie = Request.Cookies["CheckCode"];//从客户端的cookie中取值
if (cookie.Value == this.txtCode.Text.Trim())//txtCode是输入验证码的textbox的id
{
Response.Write("<script>alert('验证码正确!')</script>");
}
else
{
Response.Write("<script>alert('验证码错误!')</script>");
}
}

你在那里用就添加放那撒.

btnlogin_Click
这是一个按钮点击事件
也就是点击这个按钮执行的代码
你在vs中双击id是btnlogin的这个按钮
会自动生成
private void btnlogin_Click(object sender, System.EventArgs e)
{
}
这样一段代码
你把需要执行的代码写在这个函数里面就行