Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition phần 10

Để minh họa làm việc với các điều khiển xác nhận, tạo một dự án Trang web mới có tên ValidatorCtrls. Để bắt đầu, bốn loại TextBox (tên) (với bốn nhãn tương ứng và mô tả) vào trang của bạn. Tiếp theo, đặt một RequiredFieldValidator, RangeValidator, RegularExpressionValidator, | Simpo PDF Merge and Split Unregistered Version - http 1232 CHAPTER 32 WEB CONTROLS THEMES AND MASTER PAGES To illustrate working with these validation controls create a new Web Site project named ValidatorCtrls. To begin place four well-named TextBox types with four corresponding and descriptive Labels onto your page. Next place a RequiredFieldValidator RangeValidator RegularExpressionValidator and CompareValidator type adjacent to each respective field. Finally add a single Button and final Label see Figure 32-18 . Figure 32-18. Various validators Now that you have a UI let s walk through the process of configuring each member. The RequiredFieldValidator Configuring the RequiredFieldValidator is straightforward. Simply set the ErrorMessage and ControlToValidate properties accordingly using the Visual Studio 2008 Properties window. Here would be the resulting markup to ensure the txtRequiredField text box is not empty asp RequiredFieldValidator ID RequiredFieldValidator1 runat server ControlToValidate txtRequiredField ErrorMessage Oops Need to enter data. asp RequiredFieldValidator The RequiredFieldValidator supports an InitialValue property. You can use this property to ensure that the user enters any value other than the initial value in the related TextBox. For example when the user first posts to a page you may wish to configure a TextBox to contain the value Please enter your name . Now if you did not set the InitialValue property of the RequiredFieldValidator the runtime would assume that the string Please enter your name is valid. Thus to ensure a required TextBox is valid only when the user enters anything other than Please enter your name configure your widgets as follows Simpo PDF Merge and Split Unregistered Version - http CHAPTER 32 WEB CONTROLS THEMES AND MASTER PAGES 1233 asp RequiredFieldValidator ID RequiredFieldValidator1 runat server ControlToValidate txtRequiredField ErrorMessage Oops Need to .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã 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.