TAILIEUCHUNG - ASP.NET 4 Unleased - p 20

Nếu bạn nộp đơn trong Ví dụ 3,18 mà không cần nhập một giá trị cho tên đầu tiên và cuối cùng, xác nhận các thông báo lỗi xuất hiện trong cơ thể cả hai trang và trong việc kiểm soát ValidationSummary. Việc kiểm soát ValidationSummary hỗ trợ các thuộc tính sau:. DisplayMode-Cho phép bạn chỉ định cách các thông báo lỗi được định dạng. | 164 CHAPTER 3 Using the Validation Controls id txtLastName Runat server asp RequiredFieldValidator id reqLastName Text Required ErrorMessage Last Name is required ControlToValidate txtLastName Runat server br br asp Button id btnSubmit Text Submit Runat server div form body html FIGURE Displaying a validation summary. From the Library of Wow eBook Using the Validationsummary Control 165 If you submit the form in Listing without entering a value for the first and last name validation error messages appear in both the body of the page and in the Validationsummary control. The Validationsummary control supports the following properties DisplayMode Enables you to specify how the error messages are formatted. Possible values are BulletList List and SingleParagraph. HeaderText Enables you to display header text above the validation summary. ShowMessageBox Enables you to display a pop-up alert box. ShowSummary Enables you to hide the validation summary in the page. If you set the ShowMessageBox property to the value True and the ShowSummary property to the value False you can display the validation summary only within a pop-up alert box. For example the page in Listing displays a validation summary in an alert box see Figure . LISTING 3 @ Page Language C DOCTYPE html PUBLIC - W3C DTD XHTML Transitional EN http TR xhtml1 DTD html xmlns http 1999 xhtml head id Head1 runat server title Show Summary Popup title head body form id form1 runat server div asp ValidationSummary id ValidationSummary1 ShowMessageBox true ShowSummary false Runat server asp Label id lblFirstName Text First Name AssociatedControlID txtFirstName Runat server br asp TextBox id txtFirstName Runat server From the Library of Wow eBook 166 CHAPTER 3 Using the Validation Controls asp RequiredFieldValidator id reqFirstName ErrorMessage First Name is required ControlToValidate txtFirstName Display None Runat server