ASP.net编程的问题50
using System;using System.Drawing;
using System.Drawing.Imaging;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string checkCodeString = "0123456789qwertyuipolkjhgfdsaxvbnm";
int length = checkCodeString.Length;
Font font = new Font("黑体", 12, FontStyle.Bold);
Brush brush = null;
Color brushColor = new Color();
string chectCode = string.Empty;
string code = string.Empty;
Bitmap image = new Bitmap(80, 40);
Graphics g = Graphics.FromImage(image);
g.Clear(Color.White);
Random random = new Random();
for (int i = 0; i < 4; i++)
{
int current = random.Next(length);
code = checkCodeString.Substring(current, 1);
chectCode = chectCode + code;
brushColor = Color.FromArgb(random.Next(255), random.Next(255), random.Next(255));
brush = new SolidBrush(brushColor);
g.DrawString(code, font, brush, i * 15 + 2, 2);
}
Response.Clear();
Response.ContentType = "image/pjpeg";
image.Save(Response.OutputStream, ImageFormat.Jpeg);
Session["CheckCode"] = chectCode;
image.Dispose();
Response.ContentType = "text/html";
}
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text == Session["CheckCode"])
{
Response.Write("<script language='javascript'>alert('通过验证')</script>");
}
else
{
Response.Write("<script language='javascript'>alert('验证不通过')</script>");
}
}
}
打开网页后Textbox1不见了???
为什么????