How to enable and disable the ASP.NET Validation Controls


How to enable and disable the ASP.NET Validation Controls

How to enable and disable the ASP.NET Validation Controls
Abstract
Here we will discuss about how to disable and enable the ASP.NET Validation Controls.

For Example:-


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Username <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="User Name cannot be blank"></asp:RequiredFieldValidator>
<asp:Button ID="Button2" runat="server" Text="Save" />
<asp:Button ID="Button1" runat="server" Text="Close" />
</div>
</form>
</body>
</html>


Just take the above code and run it.In run time if you give username as blank then click the any one button.The "User Name cannot be blank" validation message will appear.

Disabling both Client-Side and Server-Side Validation:-
when you click the button2 no need to show the validation message means just set CausesValidation="False"(Default is True).

Disabling Client-Side Validation:-
To disable client-side validation, set the validation control's EnableClientScript property to false.


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: