Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Đối với nhân viên tra cứu logic, tạo ra một lớp đơn giản được gọi là HumanResources.cs, và chép đoạn code trong danh sách 1.7.Danh sách 1,7 Một lớp học đơn giản mà trả về số lượng nhân viên trong một bộ phận Hình 1,10 Các mẫu ASP.NET AJAX-Enabled Web Site tạo ra một trang web tham chiếu ASP.NET AJAX lắp ráp | Introducing ASP.NET AJAX 24 CHAPTER 1 Figure 1.10 The ASP.NET AJAX-Enabled Web Site template creates a website that references the ASP.NET AJAX assembly and configures the web.config file for Ajax integration. For the employee lookup logic create a simple class called HumanResources.cs and copy the code in listing 1.7. Listing 1.7 A simple class that returns the number of employees in a department using System public static class HumanResources public static int GetEmployeeCount string department int count 0 switch department case Sales count 10 break case Engineering count 28 break case Marketing ASP.NET AJAX in action 25 count 44 break case HR count 7 break default break return count The HumanResources class contains one method GetEmployeeCount which takes the department name as a parameter. It uses a simple switch statement to retrieve the number of employees in the department. To keeps things simple we hardcoded the department names and values. When you created the new website a default page named Default.aspx was also generated. Listing 1.8 shows the initial version of the page. Listing 1.8 Default page created by the ASP.NET AJAX-Enabled Web Site template @ Page Language C AutoEventWireup true CodeFile Default.aspx.cs Inherits _Default 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 Untitled Page title head body ScriptManager form id form1 runat server control asp ScriptManager ID ScriptManager1 runat server --- div div form body html What s different in this page from the usual default page created by Visual Studio is the addition of the ScriptManager control. We briefly defined the ScriptManager earlier in the chapter as the brains of an Ajax-enabled page. In this example all you need to know about the ScriptManager is that it s required to Ajax-enable a 26 CHAPTER 1 Introducing ASP.NET AJAX page it s responsible for delivering the client-side scripts to the