RequiredFieldValidatorSummary DisplayMode : ValidationSummary « Validation « ASP.NET Tutorial

ASP.NET Tutorial
1. ASP.Net Instroduction
2. Language Basics
3. ASP.net Controls
4. HTML Controls
5. Page Lifecycle
6. Response
7. Collections
8. Validation
9. Development
10. File Directory
11. Sessions
12. Cookie
13. Cache
14. Custom Controls
15. Profile
16. Configuration
17. LINQ
18. ADO.net Database
19. Data Binding
20. Ajax
21. Authentication Authorization
22. I18N
23. Mobile
24. WebPart
25. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
ASP.NET Tutorial » Validation » ValidationSummary 
8. 13. 4. RequiredFieldValidatorSummary DisplayMode
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="Default_aspx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Required Field Validation</title>
</head>
<body>
    <form runat="server" ID="frmBugs">
      <asp:Label ID="lblMsg" 
                  Text="Please report your bug here" 
                  ForeColor="red" Font-Name="Verdana" 
                  Font-Size="10" runat=server />
      <ASP:DropDownList id=ddlBooks runat=server>
                     <asp:ListItem>-- Please Pick A Book --</asp:ListItem>
                     <asp:ListItem>Programming ASP.NET</asp:ListItem>
                     <asp:ListItem>Programming .NET Windows Applications</asp:ListItem>
                     <asp:ListItem>Programming C#</asp:ListItem>
                     <asp:ListItem>Programming Visual Basic 2005</asp:ListItem>
                     <asp:ListItem>
                        Teach Yourself C++ In 21 Days
                     </asp:ListItem>
                     <asp:ListItem>
                        Teach Yourself C++ In 24 Hours
                     </asp:ListItem>
                     <asp:ListItem>TY C++ In 10 Minutes</asp:ListItem>
                     <asp:ListItem>TY More C++ In 21 Days</asp:ListItem>
                     <asp:ListItem>C++ Unleashed</asp:ListItem>
                  </ASP:DropDownList>
               </td>
               <!-- Validator for the drop down -->
               <td align=center rowspan=1>
                  <asp:RequiredFieldValidator 
                  id="reqFieldBooks" 
                  ControlToValidate="ddlBooks" 
                  Display="Static" 
                  InitialValue="-- Please Pick A Book --" 
                  ErrorMessage = "You did not choose a book from the drop-down"
                  Width="100%" runat=server> * </asp:RequiredFieldValidator>
               <td>
                  <ASP:RadioButtonList id=rblEdition 
                  RepeatLayout="Flow" runat=server>
                     <asp:ListItem>1st</asp:ListItem>
                     <asp:ListItem>2nd</asp:ListItem>
                     <asp:ListItem>3rd</asp:ListItem>
                     <asp:ListItem>4th</asp:ListItem>
                  </ASP:RadioButtonList>
               </td>
                <td align=center rowspan=1>
                  <asp:RequiredFieldValidator 
                  id="reqFieldEdition" 
                  ControlToValidate="rblEdition" 
                  ErrorMessage = "You did not pick an edition"
                  Display="Static" 
                  InitialValue="" 
                  Width="100%" runat=server>*</asp:RequiredFieldValidator>
                  <ASP:TextBox id=txtBug 
                               runat=server 
                               width="183px" 
                               textmode="MultiLine" 
                               height="68px"/>
                  <asp:RequiredFieldValidator 
                  id="reqFieldBug" 
                  ControlToValidate="txtBug" 
                  ErrorMessage = "You must provide bug details"
                  Display="Static" 
                  Width="100%" runat=server>*</asp:RequiredFieldValidator>
                    <asp:DropDownList id="lstDisplay" 
                    AutoPostBack=true 
                    OnSelectedIndexChanged="lstDisplay_SelectedIndexChanged"
                    runat=server>
                            <asp:ListItem Selected ="true">Summary</asp:ListItem>
                            <asp:ListItem>Msg. Box</asp:ListItem>
                    </asp:DropDownList>
                    <asp:DropDownList id="lstFormat" 
                    AutoPostBack=true 
                    OnSelectedIndexChanged="lstFormat_SelectedIndexChanged"
                    runat=server>
                        <asp:ListItem>List</asp:ListItem>
                        <asp:ListItem Selected="true">Bulleted List</asp:ListItem>
                        <asp:ListItem>Single Paragraph</asp:ListItem>
                    </asp:DropDownList>
                  <ASP:Button id=btnSubmit 
                  text="Submit Bug" runat=server OnClick="btnSubmit_Click" />
         <asp:ValidationSummary 
         ID="ValSum" runat="server" 
         DisplayMode="BulletList"
         HeaderText="The following errors were found: " ShowSummary="True" />
    </div>
    </form>
</body>
</html>

File: Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default_aspx : System.Web.UI.Page 
{
  protected void btnSubmit_Click(object sender, EventArgs e)
  {
    if (Page.IsValid)
    {
      lblMsg.Text = "Page is Valid!";
    }
    else
    {
      lblMsg.Text = "Some of the required fields are empty";
    }
  }
  protected void lstFormat_SelectedIndexChanged(object sender, EventArgs e)
  {
    ValSum.DisplayMode =
       (ValidationSummaryDisplayMode)
       lstFormat.SelectedIndex;
  }
  protected void lstDisplay_SelectedIndexChanged(object sender, EventArgs e)
  {
    ValSum.ShowSummary = lstDisplay.SelectedIndex == 0;
    ValSum.ShowMessageBox = lstDisplay.SelectedIndex == 1;
  }
}
8. 13. ValidationSummary
8. 13. 1. ValidationSummary displays a list of validation errors
8. 13. 2. Important properties of ValidationSummary control
8. 13. 3. Use ValidationSummary to display message box (C#)
8. 13. 4. RequiredFieldValidatorSummary DisplayMode
8. 13. 5. ValidationSummary DisplayMode=BulletList
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.