ASP. NET Server controlsIs a server component that encapsulates the user interface and its related functions. For some related articles, you can refer to the two articles, ASP. NET Server Control View analysis and ASP. NET Server Control for ASP. NET Component Design and learning.
As we all know, every server control creates corresponding objects on the server end at the cost of resources on the server end. Excessive use of server controls will greatly affect the program performance. However, the convenience and functions of server controls are incomparable to those of html controls.
The Status view attribute of the server control can automatically maintain the status of the server control during the page round-trip process, reducing developers' workload, but occupying a large amount of server memory resources. Therefore, when the server control status view is not required, set its EnableViewState attribute to false, such as common controls and controls.
Page. IsPostBack is used to record whether a Page is returned from the client. If it is set to false, it indicates that the Page is run for the first time. Otherwise, it indicates that the Page is returned from the client again.
Reasonable Application of Page. IsPostBack can avoid unnecessary operations during the round-trip process. This attribute can be used in the Page_Load function and some event functions that only need to be initialized once to improve application performance.
- void Page_Load(Object o, EventArgs e)
- { if(! Page.IsPostBack)
- {conn=new SqlConnection("server=localhost; uid=sa; pwd=; database=data");
- String sql="select * from student";
- cmd.Fill(ds,"stu");
- mydataGrid.DataBind();
- }
- }
The DataGrid Control has the most powerful data display function and has many built-in functions such as data modification, deletion, addition, and paging. If you only need to simply display the data, the DataGrid is not the best choice. The paging function and data storage method of the DataGrid Control (stored in viewstate) make it easy and convenient for program developers to use, but the resulting performance overhead is not negligible.
The DataList control has much fewer functions than the DataGrid Control. However, the customization is much stronger. The unique multi-row data display is more convenient. The functions that the DataGrid can implement.
The Repeater control has the least functions, but is very user-defined. Due to the reduction of many functions, the performance of the server is minimized.
Therefore, when you simply need to display the data list, you can select the Repeater or DataList control to achieve the same purpose and reduce the performance overhead.
This article introduces you to the server-related articles. You can view the open channels on this site. I hope this article will help you.