当前位置:编程学习 > C#/ASP.NET >>

关于验证码输入的一个怪现象!

private int SetNewValidateCode()
{Bitmap newBitmap = new Bitmap(50,20,PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(newBitmap);
g.FillRectangle(new SolidBrush(Color.White), new Rectangle(0,0,50,20));
Font textFont = new Font("Times New Roman",15);
RectangleF rectangle = new RectangleF(0,0,50,20);
Random rd = new Random();
int valationNo = 1000 + rd.Next(8999);
g.FillRectangle(new SolidBrush(Color.BurlyWood), rectangle);
g.DrawString(valationNo.ToString(), textFont, new SolidBrush(Color.Blue), rectangle);
newBitmap.Save(Server.MapPath("ValidateImage")+"\\VaImg.gif", ImageFormat.Gif);
return valationNo;}

以上代码是生成验证码的代码,验证码的大小由valationNo返回。

ValidateNum=SetNewValidateCode();

将验证码的值付给ValidateNum。

在下面的事件是一个button事件,验证ValidateTextBox中输入的验证码对不对:(与ValidateNum做比较)

private void NextStepButton_Click(object sender, System.EventArgs e)
{if(int.Parse(ValidateTextBox.Text.ToString())!=ValidateNum)
HttpContext.Current.Response.Write("<script type='text/javascript'> alert('验证码输入错误!请重新输入')</script>");
else
{user.AddUser(Session["username"].ToString(),PwdTextBox.Text,AddressTextBox.Text,MailTextBox.Text,PhoneTextBox.Tex);Response.Redirect("SuccessLogin.aspx");
}
}

我怎么最后总是输出”验证码输入错误!请重新输入“啊?也就是说怎么总执行
HttpContext.Current.Response.Write("<script type='text/javascript'> alert('验证码输入错误!请重新输入')</script>");
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,