Groups > Asp .Net > ASP.NET Tips and tricks > Re: ASP.NET Validation Controls – Important Points, Tips and Tricks




ASP.NET Validation Controls – Important Points, Tips and
Tricks

ASP.NET Validation Controls – Important Points, Tips and Tricks
Wed, 5 Mar 2008 07:08:09 +0000
ASP.NET validation controls provide an easy-to-use but powerful mechanism of
ensuring that data is entered correctly on the forms. There are 6 validation
controls included in the ASP.NET 2.0 and ASP.NET 3.5 versions. If you are not
familiar with Validation Controls in ASP.NET, here’s a recommended read for
you. Let us see some tips and tricks that can be applied to the validation
controls. These tips and tricks are for beginner and intermediate users who have
been using validation controls. Tip 1: Always use Page.IsValid before submitting
data. Apart from the other benefits, using it prevents submitting data from old
browsers that do not support javascript.Tip 2: To prevent validation to occur on
the click of the Cancel button, set the ‘CausesValidation’ property to
false<asp:ButtonID="btnCancel"Runat="server"CausesValidat
ion="False"Text="Cancel" />Tip 3: Use the
‘InitialValue’ property of the RequiredFieldValidator to validate controls
like combobox which have a default value.For eg: If your combobox has a default
item called “--Select --“ and you want that the user should select a value
other than the default value before submitting the form, then set the
‘InitialValue’ property of the RequiredFieldValidator to
“--Select--“.<asp:DropDownListID="DropDownList1"runat="ser
ver">            <asp:ListItemValue="--Select--"/>      
     <asp:ListItemValue="Item1"/>           
<asp:ListItemValue="Item2"/>           
<asp:ListItemValue="Item3"/>        </asp:DropDownList>   
   
<asp:RequiredFieldValidatorID="RequiredFieldValidator1"runat="
server"ErrorMessage="RequiredFieldValidator"ControlToValidate=&qu
ot;DropDownList1"InitialValue="--Select--"></asp:RequiredFi
eldValidator>Check out more validation control tips and tricks over here
http://www.dotnetcurry.com/ShowArticle.aspx?ID=121 Thanks.
Post Reply
Re: ASP.NET Validation Controls – Important Points, Tips and Tricks
Fri, 23 May 2008 02:19:18 +000
For those who read this tip, A small addition was made in Tip 8. Please update
your codes if you used it

HTH,

Suprotim Agarwal
Post Reply
about | contact