我的代码是这样的:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<img id="verifypic" src="ValidateCode.aspx" width="70" onclick="javascript:newverifypic();" alt="刷新验证码" height="25" /><script language="javascript" type="text/javascript">
function ckValidate(){
var vl = "<%=Session["CheckCode"] %>";//获得存储在Session中的验证码
var enterVl = document.getElementById("TextBox1").value;
if(vl != null)
{
if(enterVl.length <=0){
alert("验证码不能位空!");
}
else if(enterVl.toUpperCase() != vl.toString()){
alert("验证码错误!");
}
} } function newverifypic(){
var verify = document.getElementById("verifypic");
verify.setAttribute("src","ValidateCode.aspx?" + Math.random());
}
</script>问题是总是出现“验证码错误”,请问您能帮我解决一下吗?不甚感激!
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<img id="verifypic" src="ValidateCode.aspx" width="70" onclick="javascript:newverifypic();" alt="刷新验证码" height="25" /><script language="javascript" type="text/javascript">
function ckValidate(){
var vl = "<%=Session["CheckCode"] %>";//获得存储在Session中的验证码
var enterVl = document.getElementById("TextBox1").value;
if(vl != null)
{
if(enterVl.length <=0){
alert("验证码不能位空!");
}
else if(enterVl.toUpperCase() != vl.toString()){
alert("验证码错误!");
}
} } function newverifypic(){
var verify = document.getElementById("verifypic");
verify.setAttribute("src","ValidateCode.aspx?" + Math.random());
}
</script>问题是总是出现“验证码错误”,请问您能帮我解决一下吗?不甚感激!
将“TextBox1“改为页面源代码中<asp:TextBox/>对应的 input 控件的 id;因为服务器控件<asp:TextBox/>生成id的不是“TextBox1“
这一句不行,这样无法获得,原因是asp.net不能嵌套在js代码里,你不信你用断点看看。<%=Session["CheckCode"] %>还是<%=Session["CheckCode"] %>你可以查看源码看看也行,唯一办法是在生成时把生成的验证码赋值到一个textbox隐藏控件里,然后客户端验证填入的与这个赋值到的控件是否一样!
当然可以使用debugger;并去掉禁用脚本调试来用高度器调一下看看为什么会不相等.