Asp.net必需的字段验证器和按钮response.redirect [英] Asp.net required field validator and button response.redirect

查看:65
本文介绍了Asp.net必需的字段验证器和按钮response.redirect的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,程序员在这里遇到了一些问题.如您所见,我已经在两个文本框中添加了必填字段验证器.

Hello programmers, got a few problem here. As you see Ive added required field validator on two textboxes.

<asp:TextBox ID="txtCourseTitle" runat="server" Width="345px"></asp:TextBox>
               <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtCourseTitle"

                   ErrorMessage="needed" Font-Italic="True" Font-Size="X-Small"></asp:RequiredFieldValidator></td>
           <td>
           </td>
       </tr>
       <tr>
           <td style="width: 133px; height: 26px;">
               Course Code:</td>
           <td style="height: 26px">
               <asp:TextBox ID="txtCourseCode" runat="server" Width="345px"></asp:TextBox>
               <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtCourseCode"

                   ErrorMessage="needed" Font-Italic="True" Font-Size="X-Small"></asp:RequiredFieldValidator></td>


我的问题是,当我单击取消"按钮时,必填字段显示指出我必须在离开页面之前首先输入?单击取消按钮时,是否可以取消字段验证器?谢谢,还有更多力量
香港专业教育学院试图添加此代码,但它不起作用


My problem is when I click the cancel button the required field show stating that I have to input first before leaving the page? Is there any possible way to cancel the field validator when clicking the cancel button? Thanks and more power
Ive tried adding this code but it doesnt work

Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
      txtDuration.CausesValidation = False
      txtCourseTitle.CausesValidation = False
      btnCancel.CausesValidation = False
      Response.Redirect("CourseList.aspx")
  End Sub

推荐答案

进入取消"按钮的属性,并将CausesValidation属性设置为False.
Go into properties of cancel button and make CausesValidation property as False.


请尝试此操作

try this

<asp:button id="btnCancel" runat="server" text="Cancel" causesvalidation="false" xmlns:asp="#unknown" />


Sol1:对您的取消按钮使用Causesvalidation ="false"属性
Sol2:您可以将验证"组属性用于此取消按钮
Sol1: Use causesvalidation="false" property for your cancel button
Sol2: u can use Validation group property for this cancel button


这篇关于Asp.net必需的字段验证器和按钮response.redirect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆