{"id":9526,"date":"2021-05-01T18:18:43","date_gmt":"2021-05-01T12:48:43","guid":{"rendered":"https:\/\/www.h2kinfosys.com\/blog\/?p=9526"},"modified":"2021-05-01T18:21:23","modified_gmt":"2021-05-01T12:51:23","slug":"asp-dotnet-validators","status":"publish","type":"post","link":"https:\/\/www.h2kinfosys.com\/blog\/asp-dotnet-validators\/","title":{"rendered":"ASP.NET Validators"},"content":{"rendered":"\n<p>ASP.NET provides controls for performing validation that automatically checks user input and requires no code. You can also create custom validation for your application.<\/p>\n\n\n\n<p>Following are the validation controls:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>CompareValidator<\/li><li>RangeValidator<\/li><li>RegularExpressionValidator<\/li><li>RequiredFieldValidator<\/li><li>ValidationSummary<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>ASP.NET CompareValidator Control:<\/strong><\/h2>\n\n\n\n<p>It is used for comparing the value of an input control against the value of another input control.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ comparevalidator_demo.aspx\n&lt;%@ Page Language=\"C#\" AutoEventWireup=\"true\" CodeBehind=\"comparevalidator_demo.aspx.cs\"&nbsp;&nbsp;&nbsp;\nInherits=\"asp.netexample.comparevalidator_demo\" %&gt;&nbsp;&nbsp;\n&lt;!DOCTYPE html&gt;&nbsp;&nbsp;\n&lt;html xmlns=\"https:\/\/www.w3.org\/1999\/xhtml\"&gt;&nbsp;&nbsp;\n&lt;head runat=\"server\"&gt;&nbsp;&nbsp;\n&lt;title&gt;&lt;\/title&gt;&nbsp;&nbsp;\n&lt;style type=\"text\/css\"&gt;&nbsp;&nbsp;\n.auto-style1 {&nbsp;&nbsp;\nwidth: 100%;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;\n.auto-style2 {&nbsp;&nbsp;\nheight: 26px;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;\n.auto-style3 {&nbsp;&nbsp;\nheight: 26px;&nbsp;&nbsp;\nwidth: 93px;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;\n.auto-style4 {&nbsp;&nbsp;\nwidth: 93px;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;\n&lt;\/style&gt;&nbsp;&nbsp;\n&lt;\/head&gt;&nbsp;&nbsp;\n&lt;body&gt;&nbsp;&nbsp;\n&lt;form id=\"formValidator\" runat=\"server\"&gt;&nbsp;&nbsp;\n&lt;table class=\"auto-style1\"&gt;&nbsp;&nbsp;\n&lt;tr&gt;&nbsp;&nbsp;\n&lt;td class=\"auto-style3\"&gt;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Small number:&lt;\/td&gt;&nbsp;&nbsp;\n&lt;td class=\"auto-style2\"&gt;&nbsp;&nbsp;\n&lt;asp:TextBox ID=\"txtfirstvalue\" runat=\"server\" required=\"true\"&gt;&lt;\/asp:TextBox&gt;&nbsp;&nbsp;\n&lt;\/td&gt;&nbsp;&nbsp;\n&lt;\/tr&gt;&nbsp;&nbsp;\n&lt;tr&gt;&nbsp;&nbsp;\n&lt;td class=\"auto-style4\"&gt;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Big number:&lt;\/td&gt;&nbsp;&nbsp;\n&lt;td&gt;&nbsp;&nbsp;\n&lt;asp:TextBox ID=\"txtsecondvalue\" runat=\"server\"&gt;&lt;\/asp:TextBox&gt;&nbsp;&nbsp;\n&lt;\/td&gt;&nbsp;&nbsp;\n&lt;\/tr&gt;&nbsp;&nbsp;\n&lt;tr&gt;&nbsp;&nbsp;\n&lt;td class=\"auto-style4\"&gt;&lt;\/td&gt;&nbsp;&nbsp;\n&lt;td&gt;&nbsp;&nbsp;\n&lt;asp:Button ID=\"btnSaveButton\" runat=\"server\" Text=\"save\"\/&gt;&nbsp;&nbsp;\n&lt;\/td&gt;&nbsp;&nbsp;\n&lt;\/tr&gt;&nbsp;&nbsp;\n&lt;\/table&gt;&nbsp;&nbsp;\n&lt; asp:CompareValidator ID=\"CompareValidator\" runat=\"server\" ControlToCompare=\"txtsecondvalue\"&nbsp;&nbsp;&nbsp;\nControlToValidate=\"txtfirstvalue\" Display=\"Dynamic\" ErrorMessage=\"The first number should be smaller\" ForeColor=\"Red\"&nbsp;&nbsp;&nbsp;\nOperator=\"LessThan\" Type=\"Integer\"&gt;&lt;\/asp:CompareValidator&gt;&nbsp;&nbsp;\n&lt;\/form&gt;&nbsp;&nbsp;\n&lt;\/body&gt;&nbsp;&nbsp;\n&lt;\/html&gt;&nbsp;\n<\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/Wx2nJ63LL4KkEnrKcTRU1iKk1D63OxvNcIRUjSvWz40SitmauIUoTfKkMyYMlX2cI09ELreZuzIoaT5nDfWG94iN6nswbuzsjymyzhLTMGpfhHzY4Dr1Fxk1ndAB3_5nopQJYH8\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>ASP.NET RangeValidator Control:<\/strong><\/h2>\n\n\n\n<p>This ASP.NET validators will evaluate the value of an input control for checking that the value lies between specified ranges.<\/p>\n\n\n\n<p>It also allows us to check whether the user input is between a specified upper boundary and lower boundary. This range can be either numbers, alphabetic characters or dates.<\/p>\n\n\n\n<p>The ControlToValidateproperty is used for specifying the control to validate. The properties MinimumValue and MaximumValue are used to set minimum and maximum boundaries for the control.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ RangeValidator_demo.aspx\n&lt;%@ Page Language=\"C#\" AutoEventWireup=\"true\" CodeBehind=\"RangeValidator_demo.aspx.cs\"&nbsp;&nbsp;&nbsp;\nInherits=\"asp.netexample.RangeValidator_demo\" %&gt;&nbsp;&nbsp;\n&lt;!DOCTYPE html&gt;&nbsp;&nbsp;\n&lt;html xmlns=\"https:\/\/www.w3.org\/1999\/xhtml\"&gt;&nbsp;&nbsp;\n&lt;head runat=\"server\"&gt;&nbsp;&nbsp;\n&lt;title&gt;&lt;\/title&gt;&nbsp;&nbsp;\n&lt;style type=\"text\/css\"&gt;&nbsp;&nbsp;\n.auto-style1 {&nbsp;&nbsp;\nheight: 82px;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;\n.auto-style2 {&nbsp;&nbsp;\nwidth: 100%;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;\n.auto-style3 {&nbsp;&nbsp;\nwidth: 89px;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;\n.auto-style4 {&nbsp;&nbsp;\nmargin-left: 80px;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;\n&lt;\/style&gt;&nbsp;&nbsp;\n&lt;\/head&gt;&nbsp;&nbsp;\n&lt;body&gt;&nbsp;&nbsp;\n&lt;form id=\"formRangeValidator\" runat=\"server\"&gt;&nbsp;&nbsp;\n&lt;div class=\"auto-style1\"&gt;&nbsp;&nbsp;\n&lt;p class=\"auto-style4\"&gt;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Enter value between 100 and 200&lt;br\/&gt;&nbsp;&nbsp;\n&lt;\/p&gt;&nbsp;&nbsp;\n&lt;table class=\"auto-style2\"&gt;&nbsp;&nbsp;\n&lt;tr&gt;&nbsp;&nbsp;\n&lt;td class=\"auto-style3\"&gt;&nbsp;&nbsp;\n&lt;asp:Label ID=\"lblEnterValue\" runat=\"server\" Text=\"Enter a value\"&gt;&lt;\/asp:Label&gt;&nbsp;&nbsp;\n&lt;\/td&gt;&nbsp;&nbsp;\n&lt;td&gt;&nbsp;&nbsp;\n&lt;asp:TextBox ID=\"txtuserInput\" runat=\"server\"&gt;&lt;\/asp:TextBox&gt;&nbsp;&nbsp;\n&lt;asp:RangeValidator ID=\"RangeValidator\" runat=\"server\" ControlToValidate=\"txtuserInput\"&nbsp;&nbsp;&nbsp;\nErrorMessage=\"Enter value in specified range\" ForeColor=\"Red\" MaximumValue=\"199\" MinimumValue=\"101\"&nbsp;&nbsp;&nbsp;\nSetFocusOnError=\"True\"Type=\" Integer\"&gt;&lt;\/asp:RangeValidator&gt;&nbsp;&nbsp;\n&lt;\/td&gt;&nbsp;&nbsp;\n&lt;\/tr&gt;&nbsp;&nbsp;\n&lt;tr&gt;&nbsp;&nbsp;\n&lt;td class=\"auto-style3\"&gt; &lt;\/td&gt;&nbsp;&nbsp;\n&lt;td&gt;&nbsp;&nbsp;\n&lt;br\/&gt;&nbsp;&nbsp;\n&lt;asp:Button ID=\"btnSaveButton\" runat=\"server\" Text=\"Save\"\/&gt;&nbsp;&nbsp;\n&lt;\/td&gt;&nbsp;&nbsp;\n&lt;\/tr&gt;&nbsp;&nbsp;\n&lt;\/table&gt;&nbsp;&nbsp;\n&lt;br\/&gt;&nbsp;&nbsp;\n&lt;br\/&gt;&nbsp;&nbsp;\n&lt;\/div&gt;&nbsp;&nbsp;\n&lt;\/form&gt;&nbsp;&nbsp;\n&lt;\/body&gt;&nbsp;&nbsp;\n&lt;\/html&gt;\n<\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/Iit1s3Oc9zVL7tKdwctwiYMBX4jWg0uwLzaWKxDfpMH7h8cSsDyxjQGCMZP3UKKOGZx5ZDcr7s-G2Q5-WPGeOffqSi2e1eiDv3juaPNM5vW7mUGiE0d90az5DeBusm8OEtPfb1c\" alt=\"ASP Range 1\" title=\"\"><\/figure>\n\n\n\n<p>It will throw an error message when the input is not in range.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/4pp6daq_YWgCGYsPyCeX9Qt9J81ZujsMY_ik3GJ87nIvCjyZae2qomQl8JeySQhU7u30k0X5Ea4YDfZdy2Hz6qHQ3zM6Bq2HsH6V3M46rlEDbMA8Ha9w4_ENyM9mlKXfDL2dWQo\" alt=\"ASP Range 2\" title=\"\"><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>ASP.NET RegularExpressionValidator Control:<\/strong><\/h2>\n\n\n\n<p>This ASP.NET validators is used to validate an input control&#8217;s value against the pattern defined by a regular expression.<\/p>\n\n\n\n<p>It also allows us to check and validate predictable sequences of characters like e-mail addresses, telephone numbers, etc.<\/p>\n\n\n\n<p>The property ValidationExpression is used to specify the regular expression; this expression is used to validate input control.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ RegularExpression_Demo.aspx\n&lt;%@ Page Language=\"C#\" AutoEventWireup=\"true\" CodeBehind=\"RegularExpression_Demo.aspx.cs\"&nbsp;&nbsp;&nbsp;\nInherits=\"asp.netexample.RegularExpression_Demo\" %&gt;&nbsp;&nbsp;\n&lt;!DOCTYPE html&gt;&nbsp;&nbsp;\n&lt;html xmlns=\"https:\/\/www.w3.org\/1999\/xhtml\"&gt;&nbsp;&nbsp;\n&lt;head runat=\"server\"&gt;&nbsp;&nbsp;\n&lt;title&gt;&lt;\/title&gt;&nbsp;&nbsp;\n&lt;\/head&gt;&nbsp;&nbsp;\n&lt;body&gt;&nbsp;&nbsp;\n&lt;form id=\"formRegExValidator\" runat=\"server\"&gt;&nbsp;&nbsp;\n&lt;div&gt;&nbsp;&nbsp;\n&lt;table class=\"auto-style1\"&gt;&nbsp;&nbsp;\n&lt;tr&gt;&nbsp;&nbsp;\n&lt;td class=\"auto-style2\"&gt;Email ID&lt;\/td&gt;&nbsp;&nbsp;\n&lt;td&gt;&nbsp;&nbsp;\n&lt;asp:TextBox ID=\"txtemail\" runat=\"server\"&gt;&lt;\/asp:TextBox&gt;&nbsp;&nbsp;\n&lt;asp:RegularExpressionValidator ID=\"RegularExpressionValidator\" runat=\"server\"ControlToValidate=\"txtemail\"&nbsp;&nbsp;&nbsp;\nErrorMessage=\"Please enter valid email\" ForeColor=\"Red\" ValidationExpression=\"\\w+([-+.'_]\\w+)*@\\w+([-._]\\w+)*\\.\\w+([-._]\\w+)*\"&gt;&nbsp;&nbsp;\n&lt;\/asp:RegularExpressionValidator&gt;&nbsp;&nbsp;\n&lt;\/td&gt;&nbsp;&nbsp;\n&lt;\/tr&gt;&nbsp;&nbsp;\n&lt;tr&gt;&nbsp;&nbsp;\n&lt;td class=\"auto-style2\"&gt;&lt;\/td&gt;&nbsp;&nbsp;\n&lt;td&gt;&nbsp;&nbsp;\n&lt;br\/&gt;&nbsp;&nbsp;\n&lt;asp:Button ID=\"btnSaveButton\" runat=\"server\" Text=\"Save\"\/&gt;&nbsp;&nbsp;\n&lt;\/td&gt;&nbsp;&nbsp;\n&lt;\/tr&gt;&nbsp;&nbsp;\n&lt;\/table&gt;&nbsp;&nbsp;\n&lt;\/div&gt;&nbsp;&nbsp;\n&lt;\/form&gt;&nbsp;&nbsp;\n&lt;\/body&gt;&nbsp;&nbsp;\n&lt;\/html&gt;&nbsp;\n<\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p>It produces the following output when viewing in the browser.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/xja7mZXct1vGw9g8FQpyjcBiLgYAEYQ74pcxSn61n3uvAGB67OJdf_wehhBX7_qRo_SnxUiMF-E_ip8PI4FoLUMFQTUxEzWBEB-TOcg1B1LjMQiKN3IEIaYiTxUy-JCyEdiZqQw\" alt=\"ASP Regular 1\" title=\"\"><\/figure>\n\n\n\n<p>It will validate the e-mail format as we specified in the regular expression. If validation fails, it will throw an error message.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/AMtUFJZL8eeDUXMNRLaPJv1WltaO0xI-_FyddVb8VuEvPa8MMB00UNXLjLl-70y2VSMxm7q-D-gODYUK7UNZi1fRMhcY09qnYCB2r-oWfpguxKpmU_h_YPJQjTUzHMssOP2s_hk\" alt=\"ASP Regular 2\" title=\"\"><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>ASP.NET RequiredFieldValidator Control:<\/strong><\/h2>\n\n\n\n<p>RequiredFieldValidator is used to make an input control required which will throw an error if the user leaves input control empty.<\/p>\n\n\n\n<p>It is also used to mandate form control required and restrict the user from providing data.<\/p>\n\n\n\n<p>It can remove extra spaces from the beginning and end of the input value before validation is performed.<\/p>\n\n\n\n<p>The ControlToValidateproperty must be set with the ID of the control to validate.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ RequiredFieldValidator_demo.aspx\n&lt;%@ Page Language=\"C#\" AutoEventWireup=\"true\" CodeBehind=\"RequiredFieldValidator_demo.aspx.cs\"&nbsp;&nbsp;&nbsp;\nInherits=\"asp.netexample.RequiredFieldValidator_demo\" %&gt;&nbsp;&nbsp;\n&lt;!DOCTYPE html&gt;&nbsp;&nbsp;\n&lt;html xmlns=\"https:\/\/www.w3.org\/1999\/xhtml\"&gt;&nbsp;&nbsp;\n&lt;head runat=\"server\"&gt;&nbsp;&nbsp;\n&lt;title&gt;&lt;\/title&gt;&nbsp;&nbsp;\n&lt;style type=\"text\/css\"&gt;&nbsp;&nbsp;\n.auto-style1 {&nbsp;&nbsp;\nwidth: 100%;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;\n.auto-style2 {&nbsp;&nbsp;\nwidth: 165px;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;\n&lt;\/style&gt;&nbsp;&nbsp;\n&lt;\/head&gt;&nbsp;&nbsp;\n&lt;body&gt;&nbsp;&nbsp;\n&lt;form id=\"formFieldValidator\" runat=\"server\"&gt;&nbsp;&nbsp;\n&lt;div&gt;&nbsp;&nbsp;\n&lt;\/div&gt;&nbsp;&nbsp;\n&lt;table class=\"auto-style1\"&gt;&nbsp;&nbsp;\n&lt;tr&gt;&nbsp;&nbsp;\n&lt;td class=\"auto-style2\"&gt;User Name&lt;\/td&gt;&nbsp;&nbsp;\n&lt;td&gt;&nbsp;&nbsp;\n&lt;asp:TextBox ID=\"txtname\" runat=\"server\"&gt;&lt;\/asp:TextBox&gt;&nbsp;&nbsp;\n&lt;asp:RequiredFieldValidatorIDasp:RequiredFieldValidatorID=\"user\" runat=\"server\" ControlToValidate=\"txtname\"&nbsp;&nbsp;&nbsp;\nErrorMessage=\"Please enter a user name.\" ForeColor=\"Red\"&gt;&lt;\/asp:RequiredFieldValidator&gt;&nbsp;&nbsp;\n&lt;\/td&gt;&nbsp;&nbsp;\n&lt;\/tr&gt;&nbsp;&nbsp;\n&lt;tr&gt;&nbsp;&nbsp;\n&lt;td class=\"auto-style2\"&gt;Password&lt;\/td&gt;&nbsp;&nbsp;\n&lt;td&gt;&nbsp;&nbsp;\n&lt;asp:TextBox ID=\"txtpwd\" runat=\"server\"&gt;&lt;\/asp:TextBox&gt;&nbsp;&nbsp;\n&lt;asp:RequiredFieldValidator ID=\"pass\" runat=\"server\" ControlToValidate=\"txtpwd\" ErrorMessage=\"Please enter a password\"&nbsp;&nbsp;&nbsp;\nForeColor=\"Red\"&gt;&lt;\/asp:RequiredFieldValidator&gt;&nbsp;&nbsp;\n&lt;\/td&gt;&nbsp;&nbsp;\n&lt;\/tr&gt;&nbsp;&nbsp;\n&lt;tr&gt;&nbsp;&nbsp;\n&lt;td class=\"auto-style2\"&gt; &lt;\/td&gt;&nbsp;&nbsp;\n&lt;td&gt;&nbsp;&nbsp;\n&lt;br\/&gt;&nbsp;&nbsp;\n&lt;asp:Button ID=\"btnLoginButton\" runat=\"server\" Text=\"login\"\/&gt;&nbsp;&nbsp;\n&lt;\/td&gt;&nbsp;&nbsp;\n&lt;\/tr&gt;&nbsp;&nbsp;\n&lt;\/table&gt;&nbsp;&nbsp;\n&lt;\/form&gt;&nbsp;&nbsp;\n&lt;\/body&gt;&nbsp;&nbsp;\n&lt;\/html&gt;&nbsp;\n<\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p>It will produce the following output when view in the browser.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/-ZWhfePsMgBT7BuCExgBZj0Jm662TdVMRlPJvr6WPoRToFl2beNeNCD3foi6I1-aiulMcpb-kfMUSkhgHwZUthomJRPRFHn8lC1N8cLSOJ-21XVOBrWWzoGPDsK26wvzgD7QUOQ\" alt=\"ASP Required 1\" title=\"\"><\/figure>\n\n\n\n<p>It will throw an error message when the user login with empty controls.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/ty3mfj8ylPZR1x1eJsARBp538OkB_rIPtEy6cQO2kYwDQQXZPYF4vmyzXvsrK1Mh5buCoPcHZAwNxzOCZfN3emgNHQt-V7Ihnrz9eeJeMHFjEhX-jcSLIACSyDJObQxhmbjWwd8\" alt=\"ASP Required 2\" title=\"\"><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>ASP.NET ValidationSummary Control:<\/strong><\/h2>\n\n\n\n<p>This validator is used to display a list of all validation errors in the web form.<\/p>\n\n\n\n<p>It also allows us to summarize the error messages at a single location.<\/p>\n\n\n\n<p>We can set the DisplayMode property to display error messages as a list, bullet list, or single paragraph.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ ValidationSummery_Demo.aspx\n&lt;%@ Page Language=\"C#\" AutoEventWireup=\"true\" CodeBehind=\"ValidationSummery_Demo.aspx.cs\"&nbsp;&nbsp;&nbsp;\nInherits=\"asp.netexample.ValidationSummery_Demo\" %&gt;&nbsp;&nbsp;\n&lt;!DOCTYPE html&gt;&nbsp;&nbsp;\n&lt;html xmlns=\"https:\/\/www.w3.org\/1999\/xhtml\"&gt;&nbsp;&nbsp;\n&lt;head runat=\"server\"&gt;&nbsp;&nbsp;\n&lt;title&gt;&lt;\/title&gt;&nbsp;&nbsp;\n&lt;\/head&gt;&nbsp;&nbsp;\n&lt;body&gt;&nbsp;&nbsp;\n&lt;form id=\"formSummaryValidation\" runat=\"server\"&gt;&nbsp;&nbsp;\n&lt;div&gt;&nbsp;&nbsp;\n&lt;\/div&gt;&nbsp;&nbsp;\n&lt;table class=\"auto-style1\"&gt;&nbsp;&nbsp;\n&lt;tr&gt;&nbsp;&nbsp;\n&lt;td class=\"auto-style2\"&gt;User Name&lt;\/td&gt;&nbsp;&nbsp;\n&lt;td&gt;&nbsp;&nbsp;\n&lt;asp:TextBox ID=\"txtname\" runat=\"server\"&gt;&lt;\/asp:TextBox&gt;&nbsp;&nbsp;\n&lt;asp:RequiredFieldValidator ID=\"user\" runat=\"server\" ControlToValidate=\"txtname\"&nbsp;&nbsp;&nbsp;\nErrorMessage=\"Please enter a user name.\" ForeColor=\"Red\"&gt;*&lt;\/asp:RequiredFieldValidator&gt;&nbsp;&nbsp;\n&lt;\/td&gt;&nbsp;&nbsp;\n&lt;\/tr&gt;&nbsp;&nbsp;\n&lt;tr&gt;&nbsp;&nbsp;\n&lt;td class=\"auto-style2\"&gt;Password&lt;\/td&gt;&nbsp;&nbsp;\n&lt;td&gt;&nbsp;&nbsp;\n&lt;asp:TextBox ID=\"txtpwd\" runat=\"server\"&gt;&lt;\/asp:TextBox&gt;&nbsp;&nbsp;\n&lt;asp:RequiredFieldValidator ID=\"pass\" runat=\"server\" ControlToValidate=\"txtpwd\"&nbsp;&nbsp;&nbsp;\nErrorMessage=\"Please enter a password\" ForeColor=\"Red\"&gt;*&lt;\/asp:RequiredFieldValidator&gt;&nbsp;&nbsp;\n&lt;\/td&gt;&nbsp;&nbsp;\n&lt;\/tr&gt;&nbsp;&nbsp;\n&lt;tr&gt;&nbsp;&nbsp;\n&lt;td class=\"auto-style2\"&gt;&nbsp;&nbsp;\n&lt;br\/&gt;&nbsp;&nbsp;\n&lt;asp:Button ID=\"btnLoginButton\" runat=\"server\"Text=\"login\"\/&gt;&nbsp;&nbsp;\n&lt;\/td&gt;&nbsp;&nbsp;\n&lt;td&gt;&nbsp;&nbsp;\n&lt;asp:ValidationSummary ID=\"ValidationSummary\" runat=\"server\" ForeColor=\"Red\"\/&gt;&nbsp;&nbsp;\n&lt;br\/&gt;&nbsp;&nbsp;\n&lt;\/td&gt;&nbsp;&nbsp;\n&lt;\/tr&gt;&nbsp;&nbsp;\n&lt;\/table&gt;&nbsp;&nbsp;\n&lt;\/form&gt;&nbsp;&nbsp;\n&lt;\/body&gt;&nbsp;&nbsp;\n&lt;\/html&gt;&nbsp;\n<\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p>It produces the following output when viewing in the browser.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/Np8-4u_QMaD0udaKbEEl3vwS3X5wkJUXmFYgbzZfwi7u6YMQiO8z0VmddTVR0bBrvf8r09OJlSNz9QhQIAu02ayZywHDWmit083gEaEMc2yMOhA50WlUmCPOxZkJuc3fNJvzMwQ\" alt=\"ASP Validation summary 1\" title=\"\"><\/figure>\n\n\n\n<p>It throws an error summary when the user login without credentials.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/ACHeATBhc1ph-vJ7yXtxSe5a7zimMqTVf7E0Rex1CDpo8R7xzeHTGwNJOnuuQc-TVi7f5Ue6R23iais9euKvOgP5elF6Kox58T8844vAoT-lpM7unxovV6IOJ6SC0T-YvJWJpbE\" alt=\"ASP Validation summary 2\" title=\"\"><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>ASP.NET provides controls for performing validation that automatically checks user input and requires no code. You can also create custom validation for your application. Following are the validation controls: CompareValidator RangeValidator RegularExpressionValidator RequiredFieldValidator ValidationSummary ASP.NET CompareValidator Control: It is used for comparing the value of an input control against the value of another input control. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":9530,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[499],"tags":[],"class_list":["post-9526","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet-tutorials"],"_links":{"self":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/9526","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/comments?post=9526"}],"version-history":[{"count":0,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/9526\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media\/9530"}],"wp:attachment":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media?parent=9526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/categories?post=9526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/tags?post=9526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}