(1). Description
It is easier to use a tree to display menus and item lists (retrieve data from the server). Currently, a tree can be displayed in either of the following ways:
1. During tree initialization, all data is obtained from the server at a time. After the data is obtained, data is no longer required when the page is expanded or shrunk,
In this way, the validity rate of retrieved data is relatively high, but when there are many Tree nodes, there will be a great delay in each initialization.
2. Only the expanded nodes are loaded during initialization. When you need to view the data under a node, the data is retrieved again. In this way, the initialization delay will be
Reduce, but each time you click a node, You need to obtain the data, and the page needs to be refreshed every time, so there will be a delay.
This example uses ajax to implement the second method. Each time only the node data to be expanded is dynamically loaded (when the closed node is not expanded
In addition, the page is not refreshed when the node is loaded.
(2) running example Diagram
(3) Introduction to. ajaxpro. net
First, we will introduce ajaxpro. net. ajaxpro. NET is an excellent Ajax framework. In actual applications, you only need to add its DLL
Reference and perform simple configuration, that is, you can easily directly call the server method on the client to obtain the tree node.
(4) use ajaxpro. Net pre-Configuration
1. Add a reference to the ajaxpro. dll file (exampleCode).
2. Add the following configuration in the web. config file,
1 < Httphandlers >
2 < Add verb = " Post, get " Path = " Ajaxpro/*. ashx " Type = " Ajaxpro. ajaxhandlerfactory, ajaxpro " />
3 </ Httphandlers > 3. Add the following code to the page_load event of *. aspx. CS on the page to use the ajaxpro. NET Framework: Ajaxpro. Utility. registertypeforajax ( Typeof (_ Default )); 4. After the preceding three steps, you only need to add the attribute [ajaxmethod] before the method on the backend server: 1 [Ajaxmethod ()] // Or [ajaxpro. ajaxmethod]
2 Public Arraylist getsearchitems ( String Strquery)
3 {
4 // Generate data sources
5 Arraylist items = New Arraylist ();
6 Items. Add ( " King " );
7 Items. Add ( " Rose " );
8 Return Items;
9 }
10 You can directly use the server method on the client, which is very convenient. The client calls the background Code as follows: VaR returnvalue = Background code class name. getsearchitems (parameter ); Code: www.cnitblog.com/files/chengking/ajaxpro.net_efficienttree.rar Article Referenced from: