Export (0) Print
Expand All

ValidationSummary Class

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

Namespace: System.Web.UI.MobileControls
Assembly: System.Web.Mobile (in system.web.mobile.dll)

public class ValidationSummary : MobileControl
public class ValidationSummary extends MobileControl
public class ValidationSummary extends MobileControl

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

Although the ValidationSummary class of the ASP.NET mobile controls mimics the behavior of the Web Forms ValidationSummary class in many ways, 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.

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 event handler determines if there is an error, and then either launches the form containing the ValidationSummary, or the congratulatory thank you form.

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

<script runat="server">
    private void Page_Load(Object sender, EventArgs e)
    {
        // Define validation expressions.
        UserNameExprValidator.ValidationExpression = 
            "^[a-zA-Z](.{1,9})$";
        PhoneExprValidator.ValidationExpression =
            "((\\(\\d{3}\\) ?)|(\\d{3}-))?\\d{3}-\\d{4}";
        UserNameReqValidator.Text = "User name required";
        UserNameExprValidator.Text = 
            "Must be 2-10 characters";
        PhoneExprValidator.Text = 
            "Requires a valid number: 425-555-0187";
        // ErrorMessages appear in ValidationSummary.
        UserNameExprValidator.ErrorMessage = 
            "User name must be 2-10 characters";
        UserNameReqValidator.ErrorMessage = 
            "User name required";
        PhoneExprValidator.ErrorMessage = 
            "Valid number required: 425-555-0187";
    }

    private void OnCmdClick(Object sender, EventArgs e)
    {
        if (Page.IsValid)
            ActiveForm = Form2;
        else
        {
            ValSummary.BackLabel = "Return to Form";
            ActiveForm = Form3;
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:Form runat="server" id="Form1">
        <mobile:Label runat="server" id="HeadingLabel" 
            Text="Provide your name and number" 
            StyleReference="title" />
        <mobile:Label runat="server" id="UserNameLabel" 
            Text="User Name (req'd)" />
        <mobile:Textbox  runat="server" id="UserNameTextBox"/>
        <mobile:RequiredFieldValidator runat="server" 
            id="UserNameReqValidator" 
            ControlToValidate="UserNameTextBox" />
        <mobile:RegularExpressionValidator runat="server" 
            id="UserNameExprValidator" 
            ControlToValidate="UserNameTextBox" />
        <mobile:Label runat="server" id="PhoneLabel" 
            Text="Phone" />
        <mobile:Textbox  runat="server" id="PhoneTextBox"/>
        <mobile:RegularExpressionValidator runat="server" 
            id="PhoneExprValidator" 
            ControlToValidate="PhoneTextBox" />
        <mobile:Command runat="server" id="Cmd1" 
            text="Submit" OnClick="OnCmdClick"/>
    </mobile:Form>
    <mobile:Form runat="server" id="Form2" >
        <mobile:Label ID="Label1" runat="server" 
            Text="Thank You." />
    </mobile:Form>
    <mobile:Form ID="Form3" Runat="server">
        <mobile:ValidationSummary ID="ValSummary" 
            FormToValidate="Form1" 
            HeaderText="Error Summary:" 
            runat="server" />
    </mobile:Form>
</body>
</html>

System.Object
   System.Web.UI.Control
     System.Web.UI.MobileControls.MobileControl
      System.Web.UI.MobileControls.ValidationSummary

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1

Community Additions

ADD
Show:
© 2014 Microsoft