title: How to stop redirecting to next page when validation fails?
body: <p>I have put validation on controls like TextBox on a Form in ASP.NET. When validation fails it is still redirecting to next page. How do I resolve this?</p>
  
  <pre><code>&lt;div class="inp-cont forget-success-hide"&gt;
     &lt;label for="inputFirstName"&gt;Name &lt;span class="text-error"
        style="Color:Red"&gt;*&lt;/span&gt;&lt;/label&gt;
     &lt;asp:TextBox runat="server" class="signininput" ID="txtname" placeholder="Enter Your
        Name"&gt;&lt;/asp:TextBox&gt;
     &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ForeColor="Red"
        ValidationGroup="rg" ErrorMessage="Please enter Your Name"
        ControlToValidate="txtname"&gt;&lt;/asp:RequiredFieldValidator&gt;
     &lt;br/&gt;
     &lt;asp:RegularExpressionValidator ID="RegularExpressionValidator3"
        runat="server" ControlToValidate="txtname" ErrorMessage="Only
        alphabets are allowed" ForeColor="Red"
        ValidationExpression="[a-zA-Z]+" &gt; &lt;/asp:RegularExpressionValidator&gt;
  &lt;/div&gt;
  &lt;div class="inp-cont forget-success-hide"&gt;
     &lt;label for="inputFirstName"&gt;Email &lt;span class="text-error"
        style="Color:Red"&gt;*&lt;/span&gt;&lt;/label&gt;
     &lt;asp:TextBox runat="server" class="signininput" ID="txtemail" placeholder="Enter Your Email
        Id"&gt;&lt;/asp:TextBox&gt;
     &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ForeColor="Red"
        ValidationGroup="rg" ErrorMessage="Please enter email id"
        ControlToValidate="txtemail"&gt;&lt;/asp:RequiredFieldValidator&gt;
     &lt;br /&gt;
     &lt;asp:RegularExpressionValidator ID="rv" runat="server"
        ControlToValidate="txtemail" ForeColor="Red" ValidationGroup="rg"
        ErrorMessage="Enter vaild email id"
        ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"&gt;&lt;/asp:RegularExpressionValidator&gt;
     &lt;asp:Label ID="lblemail" ForeColor="Red" runat="server" Visible="false"&gt;&lt;/asp:Label&gt;
  &lt;/div&gt;
  &lt;div class="inp-cont forget-success-hide"&gt;
     &lt;label for="inputLastName"&gt;Gender &lt;span class="text-error"
        style="Color:Red"&gt;*&lt;/span&gt;&lt;/label&gt;
     &lt;asp:DropDownList ID="ddlGender" runat="server" class="signininput" Width="100%"&gt;
        &lt;asp:ListItem Text="Select Gender" Value="0"&gt;&lt;/asp:ListItem&gt;
        &lt;asp:ListItem Text="Male" Value="1"&gt;&lt;/asp:ListItem&gt;
        &lt;asp:ListItem Text="Female" Value="2"&gt;&lt;/asp:ListItem&gt;
     &lt;/asp:DropDownList&gt;
     &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ForeColor="Red"
        ValidationGroup="rg" ErrorMessage="Please select gender"
        InitialValue="0"
        ControlToValidate="ddlGender"&gt;&lt;/asp:RequiredFieldValidator&gt;
  &lt;/div&gt;
  &lt;div class="inp-cont forget-success-hide"&gt;
     &lt;label for="inputEMail"&gt;Password &lt;span class="text-error"
        style="Color:Red"&gt;*&lt;/span&gt;&lt;/label&gt;
     &lt;asp:TextBox runat="server" class="signininput" ID="txtpwd" MaxLength="20" TextMode="Password"
        placeholder="Enter Your Password"&gt;&lt;/asp:TextBox&gt;
     &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ForeColor="Red"
        ValidationGroup="rg" ErrorMessage="Please enter password" 
        ControlToValidate="txtpwd"&gt;&lt;/asp:RequiredFieldValidator&gt;
  &lt;/div&gt;
  &lt;div class="inp-cont forget-success-hide"&gt;
     &lt;label for="inputEMail"&gt;Confirm Password &lt;span class="text-error"
        style="Color:Red"&gt;*&lt;/span&gt;&lt;/label&gt;
     &lt;asp:TextBox runat="server" class="signininput" ID="txtcpwd" MaxLength="20" TextMode="Password"
        placeholder="Enter Confirm Password"&gt;&lt;/asp:TextBox&gt;
     &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ForeColor="Red"
        ValidationGroup="rg" ErrorMessage="Please enter confirm password" 
        ControlToValidate="txtcpwd"&gt;&lt;/asp:RequiredFieldValidator&gt;
     &lt;br /&gt;
     &lt;asp:CompareValidator ID="cmp" runat="server" ForeColor="Red" ValidationGroup="rg"
        ErrorMessage="Password does not match" ControlToCompare="txtpwd"
        ControlToValidate="txtcpwd"  Type="String"
        Operator="Equal"&gt;&lt;/asp:CompareValidator&gt;
     &lt;asp:Label ID="lblpwd" ForeColor="Red" runat="server" Visible="false"&gt;&lt;/asp:Label&gt;
  &lt;/div&gt;
  &lt;div class="inp-cont forget-success-hide"&gt;
     &lt;label for="inputMob"&gt;Mobile No &lt;span class="text-error" style="Color:Red"&gt;*&lt;/span&gt;&lt;/label&gt;
     &lt;asp:TextBox runat="server" MaxLength="10" class="signininput"
        onkeypress="inputNumberOnly(event)" ID="txtmobno" placeholder="Enter
        Your Mobile"&gt;&lt;/asp:TextBox&gt;
     &lt;%--&lt;asp:RegularExpressionValidator ID="RegularExpressionValidator1"
        runat="server" ControlToValidate="txtmobno"
                                                                                ValidationGroup="rg"  ForeColor="Red" ErrorMessage="Enter a valid
        phone number"
                                                                                 ValidationExpression="^[7-9][0-9](\s){0,1}(\-){0,1}(\s){0,1}[0-9]{1}[0-9]{7}$"&gt;&lt;/asp:RegularExpressionValidator&gt;&lt;br
        /&gt;--%&gt;
     &lt;asp:RegularExpressionValidator ID="RegularExpressionValidator1"
        runat="server" ControlToValidate="txtmobno"
        ValidationGroup="rg"  ForeColor="Red" ErrorMessage="Enter a valid
        mobile number"
        ValidationExpression="^[789]\d{9}$"&gt;&lt;/asp:RegularExpressionValidator&gt;
     &lt;br
        /&gt;
     &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ForeColor="Red"
        ValidationGroup="rg" ErrorMessage="Please enter mobile number" 
        ControlToValidate="txtmobno"&gt;&lt;/asp:RequiredFieldValidator&gt;
  &lt;/div&gt;
  </code></pre>