Click here to Skip to main content
15,113,855 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 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
  End Sub

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: Use causesvalidation="false" property for your cancel button
Sol2: u can use Validation group property for this cancel button

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900