Export (0) Print
Expand All

ValidationSummary Control

.NET Framework 1.1

This control displays a summary of all the validation errors that occurred during the rendering of a form.

Mobile Controls Syntax

Required properties, defaults, and code-featured elements are noted in bold type.

<mobile:ValidationSummary
   runat="server"
   id="id"
   Font-Name="fontName"
   Font-Size="{NotSet|Normal|Small|Large}"
   Font-Bold="{NotSet|False|True}"
   Font-Italic="{NotSet|False|True}"
   ForeColor="foregroundColor"
   BackColor="backgroundColor"
   Alignment="{NotSet|Left|Center|Right}"
   StyleReference="styleReference"
   Wrapping="{NotSet|Wrap|NoWrap}"

   FormToValidate="FormID"
   BackLabel="[BackLabel]">
</mobile:ValidationSummary>

Containment Rules

The following controls can contain a ValidationSummary control.

Control Comments
System.Web.UI.MobileControls.Form Can contain any number of ValidationSummary controls.
System.Web.UI.MobileControls.Panel Can contain any number of ValidationSummary controls.

The ValidationSummary control cannot contain any additional controls.

Device Templates

None.

Device-Specific Behavior

For all renderings, the StyleReference property is initially set to Error. It will use the error style for the page style sheet or, if a style sheet for the page does not exist, it will use the system default style sheet.

The ValidationSummary control renders by displaying the value of the HeaderText property first, followed by an HTML or WML list that consists of the following items:

  • The ErrorMessage properties of each validator on the invalid form.
  • A Link control is rendered with the invalid form as its target and with the text of the value of the BackLabel property.

On all devices, if the form that you want to validate is valid, the ValidationSummary control does not render anything.

Device language Description of behavior
HTML The current style of the control is applied as it is to all HTML renderings.
WML Each ErrorMessage property is preceded by "- " (hyphen followed by space).

Example

This example demonstrates two methods of displaying validation errors: one inline, and one using the summary format.

<%@ Page Inherits=
   "System.Web.UI.MobileControls.MobilePage" Language="VB" %>
<%@ Register TagPrefix="mobile"
    Namespace="System.Web.UI.MobileControls"
    Assembly="System.Web.Mobile" %>

<script language="vb" runat="server">

Protected Sub Summary_Click(sender As Object, e As EventArgs)
  ' Hide or show Back link. This is because ValidationSummary
  ' doesn't provide the Back link when validation succeeds.
   BackLink.Visible = Page.IsValid
   ActiveForm = Form2
End Sub

Sub ServerValidate (source As object, args As ServerValidateEventArgs)
  Dim num as Int32
  num = Int32.Parse(number.Text)
  args.IsValid = ((num Mod 2) = 0)
End Sub
</script>

<mobile:Form id="Form1" runat="server">

  <mobile:RangeValidator runat="server"
   ControlToValidate="number"
   Type="Integer"
   MaximumValue="5"
   MinimumValue="1"
   ErrorMessage="The input number should be with in the range 1 - 5.">

    Please enter a number of value 1 - 5

  </mobile:RangeValidator>

  <mobile:RegularExpressionValidator runat="server"
       ControlToValidate="number"
       ValidationExpression="\b\d{1}\b"
       ErrorMessage="The input number should be a single digit.">
   Please enter a single digit
  </mobile:RegularExpressionValidator>

  <mobile:CustomValidator ControlToValidate="number"
         OnServerValidate="ServerValidate"
         ErrorMessage="The input number should be even."
         runat="server">
   Please enter an even number
  </mobile:CustomValidator>

  <mobile:Label runat="server">
   Please enter an even number between 1 to 5
  </mobile:Label>
  <mobile:TextBox id="number" runat="server"/>

  <mobile:Command runat="server">
   Show errors inline if not valid
  </mobile:Command>

  <mobile:Command OnClick="Summary_Click" runat="server">
   Show errors in summary
  </mobile:Command>
</mobile:Form>

<mobile:Form id="Form2" runat="server">
  <mobile:Label runat="server">
   Your input is valid if no error is shown below.
  </mobile:Label>
  <mobile:ValidationSummary FormToValidate="Form1"
                     HeaderText="Error listed below:"
                     runat="server"/>
  <mobile:Link id="BackLink" runat="server"
            NavigateUrl="#Form1"
            Visible="False"
            Text="Back" />
</mobile:Form>
[C#]
<%@ Page Inherits=
   "System.Web.UI.MobileControls.MobilePage" Language="C#" %>
<%@ Register TagPrefix="mobile"
    Namespace="System.Web.UI.MobileControls"
    Assembly="System.Web.Mobile" %>

<script language="c#" runat="server">

protected void Summary_Click(Object sender, EventArgs e)
{
  // Hide or show Back link. This is because ValidationSummary
  // doesn't provide the Back link when validation succeeds.
   BackLink.Visible = Page.IsValid;
   ActiveForm = Form2;
}

void
ServerValidate (object source, ServerValidateEventArgs args)
{
   int num = Int32.Parse(number.Text);
   args.IsValid = ((num % 2) == 0);

}
</script>

<mobile:Form id="Form1" runat="server">

  <mobile:RangeValidator runat="server"
   ControlToValidate="number"
   Type="Integer"
   MaximumValue="5"
   MinimumValue="1"
   ErrorMessage="The input number should be with in the range 1 - 5.">

    Please enter a number of value 1 - 5

  </mobile:RangeValidator>

  <mobile:RegularExpressionValidator runat="server"
       ControlToValidate="number"
       ValidationExpression="\b\d{1}\b"
       ErrorMessage="The input number should be a single digit.">
   Please enter a single digit
  </mobile:RegularExpressionValidator>

  <mobile:CustomValidator ControlToValidate="number"
         OnServerValidate="ServerValidate"
         ErrorMessage="The input number should be even."
         runat="server">
   Please enter an even number
  </mobile:CustomValidator>

  <mobile:Label runat="server">
   Please enter an even number between 1 to 5
  </mobile:Label>
  <mobile:TextBox id="number" runat="server"/>

  <mobile:Command runat="server">
   Show errors inline if not valid
  </mobile:Command>

  <mobile:Command OnClick="Summary_Click" runat="server">
   Show errors in summary
  </mobile:Command>
</mobile:Form>

<mobile:Form id="Form2" runat="server">
  <mobile:Label runat="server">
   Your input is valid if no error is shown below.
  </mobile:Label>
  <mobile:ValidationSummary FormToValidate="Form1"
                     HeaderText="Error listed below:"
                     runat="server"/>
  <mobile:Link id="BackLink" runat="server"
            NavigateUrl="#Form1"
            Visible="False"
            Text="Back" />
</mobile:Form>

See Also

ValidationSummary Class | ValidationSummary Class Members | ValidationSummary Control | Control Reference

Show:
© 2015 Microsoft