tailieunhanh - ASP.NET 4 Unleased - p 21

Các AjaxValidatorEvaluateIsValid () JavaScript phương pháp khởi tạo một cuộc gọi AJAX bằng cách gọi WebForm_DoCallback () phương pháp. Phương pháp này gọi là chức năng xác nhận phía máy chủ liên quan đến việc kiểm soát AjaxValidator. Khi cuộc gọi AJAX hoàn tất, các AjaxValidatorResult () phương thức được gọi. | 174 CHAPTER 3 Using the Validation Controls If there is an error show it function AjaxValidatorError message alert Error 1 message The AjaxValidatorEvaluateIsValid JavaScript method initiates an AJAX call by calling the WebForm_DoCallback method. This method calls the server-side validation function associated with the AjaxValidator control. When the AJAX call completes the AjaxValidatorResult method is called. This method updates the display of the validation control on the client. The page in Listing illustrates how you can use the AjaxValidator control. This page handles the AjaxValidator control s ServerValidate event to associate a custom validation function with the control. The page in Listing contains a form that includes fields for entering a username and favorite color. When you submit the form the values of these fields are inserted into a database table named Users. In Listing the validation function checks whether a username already exists in the database. If you enter a username that already exists a validation error message displays. The message displays in the browser before you submit the form back to the server see Figure . It is important to realize that you can associate any server-side validation function with the AjaxValidator. You can perform a database lookup call a web service or perform a complex mathematical function. Whatever function you define on the server is automatically called on the client. LISTING @ Page Language C @ Register TagPrefix custom Namespace myControls @ Import Namespace @ Import Namespace DOCTYPE html PUBLIC - W3C DTD XHTML Transitional EN http TR xhtml1 DTD script runat server summary Validation function that is called on both the client and server summary protected void AjaxValidator1_ServerValidate object source ServerValidateEventArgs args if UserNameExists From the .

TÀI LIỆU LIÊN QUAN
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.