ValidationSummary Class

Presents a summary of all the validation errors that have occurred on a form.

public class System.Web.UI.MobileControls.ValidationSummary : 
   System.Web.UI.MobileControls.MobileControl

Remarks

The ValidationSummary class creates a summary of all validation errors and presents them either inline or on a separate form. The ValidationSummary control uses the text in the ErrorMessage property for the errors that are displayed either inline or on a summary form.

Although in most respects the ValidationSummary class of the ASP.NET mobile controls mimics the behavior of the Web Forms ValidationSummary class, the mobile controls version of the class does not inherit directly from the Web Forms version of the class. Thus, properties that modify the output of the validation summary, such as the DisplayMode property, are not available in mobile controls. The mobile controls version of the summary is derived directly from the MobileControl class.

Example

The following code example demonstrates how to create an instance of a ValidationSummary class, and add it to a form in an ASP.NET mobile Web application during a page load. The user-defined Page_Load function determines if there is an error, and then either launches the form containing the ValidationSummary control, or the congratulatory Thank you form.

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

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

Sub Page_Load(sender As Object, e As EventArgs)
   ' Define validation expressions.
   revUserName.ValidationExpression = "^[a-zA-Z](.{1,9})$"
   revPhone.ValidationExpression = _
      "((\\(\\d{3}\\) ?)|(\\d{3}-))?\\d{3}-\\d{4}"

   rfvUserName.Text = "User name is required"
   revUserName.Text = "Must be between 2 to 10 characters long"
   revPhone.Text = "Please provide a valid number: (425) 555-0187"

   ' ErrorMessages appear in ValidationSummary.
   revUserName.ErrorMessage = "Incorrect UserName format. Name" + _ 
                              " can be 2 to 10 characters long"
   rfvUserName.ErrorMessage = "User name required"
   revPhone.ErrorMessage = "Please provide a valid number: " + _
                           "(425) 555-0187"
End Sub

Sub OnCmdClick1(sender As Object, e As EventArgs)
   If Page.IsValid Then
      ActiveForm = Form2
   End If
End Sub
</script>

<mobile:Form runat="server" id="Form1" >
   <mobile:Label runat="server" id="lblHeading" 
      Text="Provide your name and number" StyleReference="title" />   
   <mobile:Label runat="server" id="lblUserName" 
      Text="User Name (req'd)" />
   <mobile:Textbox  runat="server" id="txtUserName"/>
   <mobile:RequiredFieldValidator runat="server" id="rfvUserName" 
      ControlToValidate="txtUserName" />
   <mobile:RegularExpressionValidator runat="server" id="revUserName" 
      ControlToValidate="txtUserName" />
   <mobile:Label runat="server" id="lblPhone" Text="Phone" />
   <mobile:Textbox  runat="server" id="txtPhone"/>
   <mobile:RegularExpressionValidator runat="server" id="revPhone" 
      ControlToValidate="txtPhone" />
   <mobile:ValidationSummary FormToValidate="Form1"
      HeaderText="Error Summary:"
      runat="server" />
   <mobile:Command runat="server" id="Command1" text="Submit" 
      OnClick="OnCmdClick1"/>
</mobile:Form>

<mobile:Form runat="server" id="Form2" >
   <mobile:Label runat="server" Text="Thank You." />
</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 runat="server" language="c#">

void Page_Load(Object sender, EventArgs e)
{
   // Define validation expressions.
   revUserName.ValidationExpression = "^[a-zA-Z](.{1,9})$";
   revPhone.ValidationExpression = 
      "((\\(\\d{3}\\) ?)|(\\d{3}-))?\\d{3}-\\d{4}";

   rfvUserName.Text = "User name is required";
   revUserName.Text = "Must be between 2 to 10 characters long";
   revPhone.Text = "Please provide a valid number: (425) 555-0187";

   // ErrorMessages appear in ValidationSummary.
   revUserName.ErrorMessage = "Incorrect UserName format. Name" + 
                              " can be 2 to 10 characters long";
   rfvUserName.ErrorMessage = "User name required";
   revPhone.ErrorMessage = "Please provide a valid number: " +
                           "(425) 555-0187";
}

void OnCmdClick1(Object sender, EventArgs e)
{
   if (Page.IsValid)
   {
      ActiveForm = Form2;
   }
}
</script>

<mobile:Form runat="server" id="Form1" >
   <mobile:Label runat="server" id="lblHeading" 
      Text="Provide your name and number" StyleReference="title" />   
   <mobile:Label runat="server" id="lblUserName" 
      Text="User Name (req'd)" />
   <mobile:Textbox  runat="server" id="txtUserName"/>
   <mobile:RequiredFieldValidator runat="server" id="rfvUserName" 
      ControlToValidate="txtUserName" />
   <mobile:RegularExpressionValidator runat="server" id="revUserName" 
      ControlToValidate="txtUserName" />
   <mobile:Label runat="server" id="lblPhone" Text="Phone" />
   <mobile:Textbox  runat="server" id="txtPhone"/>
   <mobile:RegularExpressionValidator runat="server" id="revPhone" 
      ControlToValidate="txtPhone" />
   <mobile:ValidationSummary FormToValidate="Form1"
      HeaderText="Error Summary:"
      runat="server" />
   <mobile:Command runat="server" id="Command1" text="Submit" 
      OnClick="OnCmdClick1"/>
</mobile:Form>

<mobile:Form runat="server" id="Form2" >
   <mobile:Label runat="server" Text="Thank You." />
</mobile:Form>

Requirements

Namespace: System.Web.UI.MobileControls

Assembly: System.Web.Mobile

See Also

ValidationSummary Control