Optimal selection of ASP.net server controls

Source: Internet
Author: User
Tags html tags server memory

Reduce unnecessary server controls

The convenience and functionality that the server control brings is unmatched by the HTML control. However, each server control needs to create the appropriate object on the server side, at the expense of server-side resources, excessive use of server controls can greatly affect program performance.

In many cases, simply using HTML tags or data binding enables you to achieve the desired functionality. For example, a control that uses it to display static information can be implemented entirely with simple tags. If the HTML control does not reach the functionality you want to implement, and you cannot implement it in a scripting language such as JavaScript or VBScript, consider selecting a server control.

Disable unnecessary view of status

The State view properties of the server control can automatically maintain the state of the server control during a round trip, reducing the developer's workload, but requiring a large amount of server memory resources. Therefore, you should set its EnableViewState property to false, such as a commonly used and control, without requiring a server control state view.

The application of Page.IsPostBack

Page.IsPostBack is used to record whether the page is returned from the client, or false for the first run, otherwise the page is returned from the client. The reasonable application of page.ispostback can avoid some unnecessary operation of the page in the round trip process. This property can be used to improve application performance in the Page_Load function and in some event functions that need to be initialized only once.

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 above code will ensure that the database is read and bound only when the page is first accessed.

Rational use of the DataGrid control

The DataGrid control has the most powerful data display capabilities, as well as built-in data modification, deletion, addition, paging and many other functions. The DataGrid is not the best choice if you need to simply display the data. The paging function of the DataGrid control, how the data is stored (stored in ViewState), and so on, although it is easy and quick to use by program developers, the resulting performance overhead is not negligible.

The DataList control is much less powerful than the DataGrid feature. But the customization is much stronger. It is more convenient to display the specific multiline data. The function that the DataGrid can achieve, it basically can achieve.

Repeater controls have the least functionality, but they are very customizable. The server's performance is minimized because of the reduced functionality.

Therefore, when you simply display the list of data, selecting the Repeater or DataList control also achieves your purpose and reduces performance overhead.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.