tailieunhanh - ASP.NET 4 Unleased - p 19

Sử dụng Control CustomValidator Nếu không có các điều khiển xác nhận khác thực hiện các loại xác nhận mà bạn cần, bạn luôn có thể sử dụng kiểm soát CustomValidator. Bạn có thể kết hợp một chức năng xác nhận tuỳ chỉnh với sự kiểm soát CustomValidator. Việc kiểm soát CustomValidator có ba đặc tính quan trọng:. ControlToValidate-ID của các trường biểu mẫu được xác nhận. . Text-Các thông báo lỗi hiển thị khi xác nhận không thành công | 154 CHAPTER 3 Using the Validation Controls Using the CustomValidator Control If none of the other validation controls perform the type of validation that you need you can always use the CustomValidator control. You can associate a custom validation function with the CustomValidator control. The CustomValidator control has three important properties ControlToValidate The ID of the form field being validated. Text The error message displayed when validation fails. ClientValidationFunction The name of a client-side function used to perform client-side validation. The CustomValidator also supports one event ServerValidate This event is raised when the CustomValidator performs validation. You associate your custom validation function with the CustomValidator control by handling the ServerValidate event. For example imagine that you want to validate the length of a string entered into a form field. You want to ensure that a user does not enter more than 10 characters into a multiline TextBox control. The page in Listing contains an event handler for a CustomValidator control s ServerValidate event which checks the string s length. LISTING @ Page Language C DOCTYPE html PUBLIC - W3C DTD XHTML Transitional EN http TR xhtml1 DTD script runat server void valComments_ServerValidate Object source ServerValidateEventArgs args if 10 false else true script html xmlns http 1999 xhtml head id Head1 runat server title Show CustomValidator title head body form id form1 runat server From the Library of Wow eBook Using the CustomValidator Control 155 div asp Label id lblComments Text Comments AssociatedControlID txtComments Runat server br asp TextBox id txtComments TextMode MultiLine Columns 30 Rows 5 Runat server asp CustomValidator id valComments ControlToValidate txtComments Text Comments must be less than 10 characters OnServerValidate .

TÀI LIỆU LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
14    159    0    29-03-2024
10    112    0    29-03-2024
10    108    0    29-03-2024
1    102    1    29-03-2024
2    91    0    29-03-2024
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.