当用户更换验证码的时候怎么样保存当前页面空间的状态? 当前有TEXTBOX, RadioButtonList等控件, 主要是当用户点击刷新验证码时 页面的各个空间的都会消失,我想保存其中的值,请各位大虾指教啊。最好有示例代码哦 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 验证码页<tr> <td height="20" width="60" class="text6"> 验证码:</td> <td align="left"> <input type="text" autocomplete="off" class="input4" style="width: 60px;" name="textfield" id="Text_num" runat="server" size="8" maxlength="4" /> <a href="javascript:newVCode();"><img alt="点击刷新验证码" title="点击刷新验证码" border="0" id="vcode" height="21" width="74" src="../sub/GetVCode.aspx" tabindex="0" /></a></td> </tr> <script type="text/javascript" language="javascript">function newVCode() { url="../sub/GetVCode.aspx?updatetime="+Math.random(); document.getElementById("vcode").src=url; document.getElementById("Text_num").select(); } </script>验证码。cs//验证码 if (Session["Num"] == null) { lblmsg.Text = "<script language='javascript'>alert('请重新输入验证码!')</script>"; Text_num.Value = ""; Text_num.Focus(); return; } string strNum = Session["Num"].ToString().ToLower(); if (this.Text_num.Value.ToLower() != strNum) { lblmsg.Text = "<script language='javascript'>alert('验证码不正确!');</script>"; //lblmsg.Text = "setFocus('" + Text3.ClientID + "')"; this.Text_num.Value = ""; this.Text_num.Focus(); return; }GetVCode.aspx建立个空页面就可以GetVCode.aspx.csusing System.Drawing.Imaging;using System.IO;protected void Page_Load(object sender, EventArgs e) { //创建随机数 string strNum = Rndnum(); Session["Num"]=strNum; ValidateCode(strNum); } public string Rndnum() { int j1; string strChoice = "2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,j,k,m,n,p,q,r,s,t,u,v,w,x,y,z"; string[] strResult = strChoice.Split(','); string strReturn = ""; Random rnd = new Random(unchecked((int)DateTime.Now.Ticks)); for (int i = 0; i < 4; i++) { Random rnd1 = new Random(rnd.Next() * unchecked((int)DateTime.Now.Ticks)); j1 = rnd1.Next(31); rnd = new Random(rnd.Next() * unchecked((int)DateTime.Now.Ticks)); strReturn = strReturn + strResult[j1].ToString(); } return strReturn.ToUpper(); } public void ValidateCode(string vnum) { MemoryStream ms = new MemoryStream(); double Height = (vnum.Length) * 13; int gHeight = Convert.ToInt32(Height); Bitmap img = new Bitmap(gHeight, 20); Pen p1 = new Pen(Color.Black, 0); Graphics g = Graphics.FromImage(img); g.Clear(Color.White); Random rnd1 = new Random(); //画随机背景 //for (int i = 0; i < 30; i++) //{ // if (i % 3 == 0)//画点 // { // int x1 = rnd1.Next(img.Width); // int y1 = rnd1.Next(img.Height); // g.DrawRectangle(p1, x1, y1, 1, 1); // } //} //画图片的前景噪音点 for (int i = 0; i < 20; i++) { int x = rnd1.Next(img.Width); int y = rnd1.Next(img.Height); img.SetPixel(x, y, Color.FromArgb(rnd1.Next())); } //画一个边框 //g.DrawRectangle(new Pen(Color.PowderBlue,0),0,0,img.Width-1,img.Height-1); //画验证码字母 string[] font = { "Sydnie", "Microsoft Sans Serif" };//定义字体 int fontnum = rnd1.Next(2); Font f1 = new Font(font[fontnum], 10, FontStyle.Regular); for (int i = 0; i < vnum.Length; i++) { fontnum = rnd1.Next(2); int y = rnd1.Next(4); switch (fontnum) { //case 2: // f1 = new Font(font[fontnum], 11, FontStyle.Italic); // g.DrawString(vnum.Substring(i, 1), f1, (new SolidBrush(Color.Blue)), i * 11, y); // break; default: f1 = new Font(font[fontnum], 11, FontStyle.Regular); g.DrawString(vnum.Substring(i, 1), f1, (new SolidBrush(Color.Blue)), i * 11, y); break; } } //输出到浏览器 img.Save(ms, ImageFormat.Png); Response.ClearContent(); Response.ContentType = "image/Bmp"; Response.BinaryWrite(ms.ToArray()); g.Dispose(); Response.End(); }通过在GetVCode.aspx 生成Session["Num"] 保存验证码,在验证码页验证用户输入值是否等于Session["Num"] 这种方法可以不刷新页面 DataGridView的编辑与删除 这个排班管理研究整整三天了,还是毫无头绪!!!请各位大侠帮帮小弟 static变量的一个问题 编程设置多选框的显示字段与值字段 怎么样防止用户重复登录 散分:光盘解密的问题 我的浏览器,浏览的时候,默认字体不是宋体,怎么搞的? 哪位给一个论坛发贴得代码阿,急用, ***************请教一个数据绑定方面的问题***************** 简单问题求教 请问这段代码如何用C#编写? (ASP.NET)怎样在运行时动态更改数据访问层(DAL)的TableAdapter的ConnectionString?
<td height="20" width="60" class="text6">
验证码:</td>
<td align="left">
<input type="text" autocomplete="off" class="input4" style="width: 60px;" name="textfield"
id="Text_num" runat="server" size="8" maxlength="4" /> <a href="javascript:newVCode();"><img
alt="点击刷新验证码" title="点击刷新验证码" border="0" id="vcode" height="21" width="74" src="../sub/GetVCode.aspx"
tabindex="0" /></a></td>
</tr>
<script type="text/javascript" language="javascript">function newVCode()
{
url="../sub/GetVCode.aspx?updatetime="+Math.random();
document.getElementById("vcode").src=url;
document.getElementById("Text_num").select();
}
</script>验证码。cs//验证码
if (Session["Num"] == null)
{
lblmsg.Text = "<script language='javascript'>alert('请重新输入验证码!')</script>";
Text_num.Value = "";
Text_num.Focus();
return;
}
string strNum = Session["Num"].ToString().ToLower();
if (this.Text_num.Value.ToLower() != strNum)
{
lblmsg.Text = "<script language='javascript'>alert('验证码不正确!');</script>";
//lblmsg.Text = "setFocus('" + Text3.ClientID + "')";
this.Text_num.Value = "";
this.Text_num.Focus();
return;
}GetVCode.aspx
建立个空页面就可以
GetVCode.aspx.csusing System.Drawing.Imaging;
using System.IO;protected void Page_Load(object sender, EventArgs e)
{
//创建随机数
string strNum = Rndnum();
Session["Num"]=strNum;
ValidateCode(strNum);
}
public string Rndnum()
{
int j1;
string strChoice = "2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,j,k,m,n,p,q,r,s,t,u,v,w,x,y,z";
string[] strResult = strChoice.Split(',');
string strReturn = "";
Random rnd = new Random(unchecked((int)DateTime.Now.Ticks));
for (int i = 0; i < 4; i++)
{
Random rnd1 = new Random(rnd.Next() * unchecked((int)DateTime.Now.Ticks));
j1 = rnd1.Next(31);
rnd = new Random(rnd.Next() * unchecked((int)DateTime.Now.Ticks));
strReturn = strReturn + strResult[j1].ToString();
}
return strReturn.ToUpper();
}
public void ValidateCode(string vnum)
{
MemoryStream ms = new MemoryStream();
double Height = (vnum.Length) * 13;
int gHeight = Convert.ToInt32(Height);
Bitmap img = new Bitmap(gHeight, 20);
Pen p1 = new Pen(Color.Black, 0);
Graphics g = Graphics.FromImage(img);
g.Clear(Color.White);
Random rnd1 = new Random(); //画随机背景 //for (int i = 0; i < 30; i++)
//{
// if (i % 3 == 0)//画点
// {
// int x1 = rnd1.Next(img.Width);
// int y1 = rnd1.Next(img.Height); // g.DrawRectangle(p1, x1, y1, 1, 1); // }
//}
//画图片的前景噪音点
for (int i = 0; i < 20; i++)
{
int x = rnd1.Next(img.Width);
int y = rnd1.Next(img.Height); img.SetPixel(x, y, Color.FromArgb(rnd1.Next()));
}
//画一个边框
//g.DrawRectangle(new Pen(Color.PowderBlue,0),0,0,img.Width-1,img.Height-1);
//画验证码字母 string[] font = { "Sydnie", "Microsoft Sans Serif" };//定义字体 int fontnum = rnd1.Next(2); Font f1 = new Font(font[fontnum], 10, FontStyle.Regular);
for (int i = 0; i < vnum.Length; i++)
{
fontnum = rnd1.Next(2);
int y = rnd1.Next(4);
switch (fontnum)
{ //case 2:
// f1 = new Font(font[fontnum], 11, FontStyle.Italic);
// g.DrawString(vnum.Substring(i, 1), f1, (new SolidBrush(Color.Blue)), i * 11, y);
// break; default:
f1 = new Font(font[fontnum], 11, FontStyle.Regular);
g.DrawString(vnum.Substring(i, 1), f1, (new SolidBrush(Color.Blue)), i * 11, y);
break; } }
//输出到浏览器
img.Save(ms, ImageFormat.Png);
Response.ClearContent();
Response.ContentType = "image/Bmp";
Response.BinaryWrite(ms.ToArray());
g.Dispose();
Response.End();
}通过在GetVCode.aspx 生成Session["Num"] 保存验证码,在验证码页验证用户输入值是否等于Session["Num"]
这种方法可以不刷新页面