关于js获取验证码的问题下面是生成验证码的代码。。protected void Page_Load(object sender, EventArgs e)
{
VaildImg v = new VaildImg();
//长度
v.Length = 6;
//字体大小
v.FontSize = this.fontSize; v.Chaos = true;
v.BackgroundColor = this.backgroundColor;
v.ChaosColor = this.chaosColor;
v.CodeSerial = this.codeSerial; v.Colors = this.colors;
v.Fonts = this.fonts;
v.Padding = this.padding;
//随机生成5位长度字符串
string code = v.CreateVerifyCode(); //取随机码 v.CreateImageOnPage(code, this.Context); // 输出图片 Session["VaildCode"] = code;// 使用Cookies取验证码的值 Response.End();
}
前台调用(每次单击图片时改变图片上的验证码):
<asp:Image ID="imgValidate" runat="server" ImageUrl="~/Page/ValidateCode/VaildImg.aspx" onclick="this.src=this.src+'?'" />前台js获取验证码的代码:
var vCode = '<%=Session["VaildCode"]%>';上面的代码在页面首次加在时vCode始终是空值,需要刷新一下才能获取到值???单击图片时可以改变验证码的值,但是
var vCode = '<%=Session["VaildCode"]%>';获取的始终是一个值???有人遇到过上面的两个问题吗???急,在线等解答
谢谢!!!
{
VaildImg v = new VaildImg();
//长度
v.Length = 6;
//字体大小
v.FontSize = this.fontSize; v.Chaos = true;
v.BackgroundColor = this.backgroundColor;
v.ChaosColor = this.chaosColor;
v.CodeSerial = this.codeSerial; v.Colors = this.colors;
v.Fonts = this.fonts;
v.Padding = this.padding;
//随机生成5位长度字符串
string code = v.CreateVerifyCode(); //取随机码 v.CreateImageOnPage(code, this.Context); // 输出图片 Session["VaildCode"] = code;// 使用Cookies取验证码的值 Response.End();
}
前台调用(每次单击图片时改变图片上的验证码):
<asp:Image ID="imgValidate" runat="server" ImageUrl="~/Page/ValidateCode/VaildImg.aspx" onclick="this.src=this.src+'?'" />前台js获取验证码的代码:
var vCode = '<%=Session["VaildCode"]%>';上面的代码在页面首次加在时vCode始终是空值,需要刷新一下才能获取到值???单击图片时可以改变验证码的值,但是
var vCode = '<%=Session["VaildCode"]%>';获取的始终是一个值???有人遇到过上面的两个问题吗???急,在线等解答
谢谢!!!
js获取session,
这种做法本身就不可取......