验证控件提问! 我在前台使用了ASP。NET的CompareValidator验证控件,是用来验证验证码使用的。可是我点击提交时,直接就跳过了这步。没有进行验证,而是直接把数据发到后台去。我要如何做。才能让CompareValidator先行验证? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 前台 <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="txtVali" ControlToValidate="TextBox1" ErrorMessage="*验证码有误,请重新输入" Display="Dynamic"></asp:CompareValidator> <asp:TextBox ID="TextBox1" runat="server" Width="55" Visible="False" />后台 protected void Page_Load(object sender, EventArgs e) { TextBox1.Text = Convert.ToString(Session["ValidateCode"]); } protected void Submits(object sender, EventArgs e) { JobManager jobManager = new JobManager(); Job job = new Job(); job.UserName = txtUserName.Text.Trim(); job.Jobquestion = txtQuestion.Text.Trim(); job.JobAnsewer = txtAnswer.Text.Trim(); if (jobManager.JobFinkKey(job) != null) { Response.Redirect("ChangePwd.aspx"); } else { Response.Write("<script type='text/javascript'>alert('您所提供的资料有误,请认真填写!');location.href='ForgetKey.aspx'</script>"); } } LZ加上这段代码:protected void Submits(object sender, EventArgs e) { if (Page.isValid) { JobManager jobManager = new JobManager(); Job job = new Job(); job.UserName = txtUserName.Text.Trim(); job.Jobquestion = txtQuestion.Text.Trim(); job.JobAnsewer = txtAnswer.Text.Trim(); if (jobManager.JobFinkKey(job) != null) { Response.Redirect("ChangePwd.aspx"); } else { Response.Write(" <script type='text/javascript'>alert('您所提供的资料有误,请认真填写!');location.href='ForgetKey.aspx' </script>"); } } } 你在前台是不是有几个验证控件啊?你在CompareValidator 控件,和按钮的validGroup都设置为同一个值.再试试.. if (Page.isValid)解决了。谢谢 使用了验证控件后,要if (Page.isValid){ //your code} 关于使用模板Excle导出excel表格的问题 GRIDVIEW的问题 华信面试 还是昨天的问题 不能解决 已经有很多高手出建议了 可还是... 弹出窗体后 关于FreeTextBox3.0中imagegallery控件不能创件的问题!!! VS2003怎么可以显示出代码是第几行?怎么设置?在线等,谢谢 论坛里的“新投票”功能在asp.net下怎么实现啊? 水晶报表 将参数值从Decimal转换到DateTime失败 datagrid里日期型数据显示问题,帮帮小妹! 求一个基于3层的ASP.NET2.0的网站程序 在oninit里需要动态创建控件和设置事件,但权限处理需要用到session
ControlToValidate="TextBox1" ErrorMessage="*验证码有误,请重新输入" Display="Dynamic"></asp:CompareValidator>
<asp:TextBox ID="TextBox1" runat="server" Width="55" Visible="False" />后台 protected void Page_Load(object sender, EventArgs e)
{ TextBox1.Text = Convert.ToString(Session["ValidateCode"]);
}
protected void Submits(object sender, EventArgs e)
{
JobManager jobManager = new JobManager();
Job job = new Job(); job.UserName = txtUserName.Text.Trim();
job.Jobquestion = txtQuestion.Text.Trim();
job.JobAnsewer = txtAnswer.Text.Trim(); if (jobManager.JobFinkKey(job) != null)
{
Response.Redirect("ChangePwd.aspx");
}
else
{
Response.Write("<script type='text/javascript'>alert('您所提供的资料有误,请认真填写!');location.href='ForgetKey.aspx'</script>");
}
}
protected void Submits(object sender, EventArgs e)
{ if (Page.isValid) { JobManager jobManager = new JobManager();
Job job = new Job(); job.UserName = txtUserName.Text.Trim();
job.Jobquestion = txtQuestion.Text.Trim();
job.JobAnsewer = txtAnswer.Text.Trim(); if (jobManager.JobFinkKey(job) != null)
{
Response.Redirect("ChangePwd.aspx");
}
else
{
Response.Write(" <script type='text/javascript'>alert('您所提供的资料有误,请认真填写!');location.href='ForgetKey.aspx' </script>");
}
}
}
你在CompareValidator 控件,和按钮的validGroup都设置为同一个值.再试试..
if (Page.isValid)
{
//your code
}