Compare Page Revisions
« Older Revision - Back to Page History - Current Revision
Table of Contents [Hide/Show]
Common Properties User Feedback Types of Validation Required Field Data Type Range Validation Comparison to Another Field Custom Validation Validating User Controls
EnableClientScript
Display
runat="server" Display="Dynamic" Text="*" EnableClientScript="true" SetFocusOnError="true" ValidationGroup="MainValidationGroup"
ValidationGroup
ErrorMessage
<asp:ValidationSummary runat="server" ID="uxValidationSummary" ValidationGroup="MainValidationGroup" EnableClientScript="true" HeaderText="<b>Couldn't process your request for the following reason(s).</b>" ShowMessageBox="false" ShowSummary="true" DisplayMode="BulletList" BackColor="#ffff99" BorderColor="Red" BorderWidth="2px" Font-Bold="false" />
Text
<asp:RequiredFieldValidator runat="server" ControlToValidate="uxStartDateTextBox" Display="Dynamic" EnableClientScript="true" SetFocusOnError="true" Text="" ValidationGroup="MainValidationGroup" ID="uxStartDateRequiredValidator" ErrorMessage="Start Date must be specified." > <asp:Image runat="server" ImageUrl="~/images/Exclamation.PNG" /> </asp:RequiredFieldValidator>
<asp:RequiredFieldValidator runat="server" Display="Dynamic" EnableClientScript="true" SetFocusOnError="true" Text="*" ValidationGroup="MainValidationGroup" ControlToValidate="uxStartDateTextBox" ID="uxStartDateRequiredValidator" ErrorMessage="Start Date is required." />
<asp:RequiredFieldValidator runat="server" Display="Dynamic" EnableClientScript="true" SetFocusOnError="true" ValidationGroup="MainValidationGroup" ControlToValidate="uxStartDateTextBox" ID="uxStartDateRequiredValidator" ErrorMessage="Start Date is required." > <asp:Image ID="Image9" runat="server" ImageUrl="~/images/Exclamation.PNG" /> </asp:RequiredFieldValidator>
<asp:CompareValidator runat="server" Display="Dynamic" EnableClientScript="true" SetFocusOnError="true" Text="*" ValidationGroup="MainValidationGroup" ID="uxStartDateDataTypeValidator" ControlToValidate="uxFromDateTextBox" Operator="DataTypeCheck" Type="Date" ErrorMessage="Start Date must be a valid date." >
<asp:CompareValidator runat="server" Display="Dynamic" EnableClientScript="true" SetFocusOnError="true" ValidationGroup="MainValidationGroup" ID="uxStartDateDataTypeValidator" ControlToValidate="uxFromDateTextBox" Operator="DataTypeCheck" Type="Date" ErrorMessage="Start Date must be a valid date." > <asp:Image ID="Image9" runat="server" ImageUrl="~/images/Exclamation.PNG" /> </asp:CompareValidator>
<asp:RangeValidator runat="server" Display="Dynamic" Text="" EnableClientScript="true" SetFocusOnError="true" ValidationGroup="MainValidationGroup" ID="uxPhoneNbrRangeValidator" ErrorMessage="Phone Number must be a ten-digit number, with no punctuation." ControlToValidate="uxPhoneNbrTextBox" MinimumValue="1000000000" MaximumValue="9999999999" Type="Double" >
<asp:RangeValidator runat="server" Display="Dynamic" Text="" EnableClientScript="true" SetFocusOnError="true" ValidationGroup="MainValidationGroup" ID="uxPhoneNbrRangeValidator" ErrorMessage="Phone Number must be a ten-digit number, with no punctuation." ControlToValidate="uxPhoneNbrTextBox" MinimumValue="1000000000" MaximumValue="9999999999" Type="Double" > <asp:Image ID="Image9" runat="server" ImageUrl="~/images/Exclamation.PNG" /> </asp:RangeValidator>
<asp:CompareValidator runat="server" Display="Dynamic" Text="*" EnableClientScript="true" SetFocusOnError="true" ValidationGroup="MainValidationGroup" ID="uxEndDateRangeValidator" ControlToValidate="uxEndDateTextBox" Operator="GreaterThanEqual" ControlToCompare="uxStartDateTextBox" Type="Date" ErrorMessage="End Date must be on or after the Start Date." />
<asp:CompareValidator runat="server" Display="Dynamic" EnableClientScript="true" SetFocusOnError="true" ValidationGroup="MainValidationGroup" ID="uxEndDateRangeValidator" ControlToValidate="uxEndDateTextBox" Operator="GreaterThanEqual" ControlToCompare="uxStartDateTextBox" Type="Date" ErrorMessage="End Date must be on or after the Start Date." > <asp:Image ID="Image9" runat="server" ImageUrl="~/images/Exclamation.PNG" /> </asp:CompareValidator>
asp:CustomValidator
<asp:CustomValidator runat="server" Display="Dynamic" Text="" SetFocusOnError="true" ValidationGroup="MainValidationGroup" EnableClientScript="true" ClientValidationFunction="validateCheckBoxes" ErrorMessage="At least one option must be selected." ID="uxCheckBoxesValidator" ValidateEmptyText="true" OnServerValidate="uxCheckboxes_Validate" Text="*" />
<asp:CustomValidator runat="server" Display="Dynamic" Text="" SetFocusOnError="true" ValidationGroup="MainValidationGroup" EnableClientScript="true" ClientValidationFunction="validateCheckBoxes" ErrorMessage="At least one option must be selected." ID="uxCheckBoxesValidator" ValidateEmptyText="true" OnServerValidate="uxCheckboxes_Validate" > <asp:Image ID="Image9" runat="server" ImageUrl="~/images/Exclamation.PNG" /> </asp:CustomValidator>
Protected Sub uxCheckBoxes_Validate(ByVal source As Object, ByVal args As ServerValidateEventArgs) _ Handles uxCheckBoxesValidator1.ServerValidate, uxCheckBoxesValidator2.ServerValidate Dim checkBoxes() As CheckBox = New CheckBox() {uxCheckBox1, uxCheckBox2, uxCheckBox3, _ uxCheckBox4, uxCheckBox5, uxCheckBox6, uxCheckBox7, uxCheckBox8 } Dim somethingChecked As Boolean = False For i As Integer = 0 To checkBoxes.GetUpperBound(0) If checkBoxes(i).Checked Then somethingChecked = True Exit For End If Next args.IsValid = somethingChecked End Sub
function validateCheckBoxes(sender, e) { var selectedCheckBoxes; selectedCheckBoxes = 0; for (i = 0; i < document.forms[0].elements.length; i++) if (document.forms[0].elements[i].type == "checkbox") if (document.forms[0].elements[i].checked) selectedCheckBoxes; e.IsValid = (selectedCheckBoxes > 0); }
ControlToValidate
ValidationProperty
<ValidationProperty("ItemsChecked")> _ Partial Class UserControls_CheckedListBox ... End Class
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.