Use of server controls and HTML controls in ASP.

Source: Internet
Author: User

in ASP. NET development, the control undoubtedly brings the convenience to the developer, greatly improves the development speed, if uses the purely the support control way to develop the website, I think there is no other development tool can spell the Visual Studio (hereinafter referred to as the "vs"). A business station can be completed in 1-2 days, if the requirements of simple, estimated half a day to fix, so the development speed, estimated some people still do not believe.

However, using VS development is a support control? The answer is in the negative. This should be based on the actual situation to choose whether or not to use the server control. Below, tian-zhi hai network and everyone talk about when to use server control, and what should be used less or no server control.

First of all, use the server control, first of all to see what the nature of the site you make. If it is the enterprise station, information station these types, to consider SEO optimization, such as the site's front desk recommends less use or no server control. Why? Now do these portals, enterprise stations, information stations, small companies everywhere, plus the studio, countless, and they can do more to make more money, most of them are to their employees with the fastest speed to work out can, as long as the function to achieve, no matter how you do. Such a site is really not suitable for SEO, because the server control with more, ASP. NET in the server control to HTML tags will be more than a lot of input type= "hidden" label, that is, HTML hidden text box control, which first affect the performance of the site , the second search engine tends to read simple HTML-formatted text, the third important content at the top of the HTML page to facilitate the search engine crawl, and a large number of server controls will be the top of the HTML content occupy and so on.

Therefore, the basic is to rely on the search engine to bring you to browse the site, the front desk will be less or no server control. Some friends will ask, without the control data display more trouble. Really trouble some, originally to support a data source control, a DataGridView and other controls can be resolved, and now become necessary to implement their own. However, the resulting HTML code for these controls is still div+table, so it's not always a hassle to use the table to implement it. Similarly, we can call the background in the HTML code method, then we can directly in the HTML interface template, the need to display the data directly in the background of the method can also achieve the display of the data, such a workload is not more complex than the control, for example:

<table>

<thead>

<tr>

<td> title </td>

<td> Time </td>

</tr>

</thead>

<tbody>

<%showlist (); %>

</tbody>

</table>

above except <%showlist ();%> This is called the background showlist () method, the others are pure HTML code. In this way, we only need to output the data that needs to be displayed in Showlist with the Response.Write method:

protected void Showlist ()

{

for (int i = 0; i <; i++)

Response.Write ("<tr><td>" + i.tostring () + "title </td><td>" + DateTime.Now.ToString () + "</ Td></tr> ");

}

The resulting HTML code is:

<table>

< thead>

< tr>

< td> title </td>

< td> time </td>

</tr>

</thead>

< tbody>

< tr><td> No. 0 title </td><td>2012-6-24 10:57:23</td></tr>

< tr><td> 1th title </td><td>2012-6-24 10:57:23</td></tr>

< tr><td> 2nd title </td><td>2012-6-24 10:57:23</td></tr>

< tr><td> 3rd title </td><td>2012-6-24 10:57:23</td></tr>

< tr><td> 4th title </td><td>2012-6-24 10:57:23</td></tr>

< tr><td> 5th title </td><td>2012-6-24 10:57:23</td></tr>

< tr><td> 6th title </td><td>2012-6-24 10:57:23</td></tr>

< tr><td> 7th title </td><td>2012-6-24 10:57:23</td></tr>

< tr><td> 8th title </td><td>2012-6-24 10:57:23</td></tr>

< tr><td> 9th title </td><td>2012-6-24 10:57:23</td></tr>

</tbody>

</table>

Use this method to display the data, the HTML tag does not need to change the code can be kept, only need to change the location of the dynamic display content as a method, it is customary you will find in fact more than the use of control operations easier.

Here, some friends may ask, that does not use server controls, such as registration, login, message such as the page, users need to submit information, it is not very cumbersome to write. Like registration, leave a message, login Such page, basically do not care about the search engine in the end not collected, and just to collect user information used, so like this page, directly using the server control development speed and fast, background operation is also convenient, of course, is the preferred method.

Second, if the site is back-office management, OA system, the company's internal use of such a nature, because such a system is only provided and the system has a relationship with the people to use, do not care about SEO, search engine included these problems, so that the site does not need to be too concerned with the use of server control, How to implement the function of the page can be realized easily.

Again, some Web pages are more dynamic, as you need to decide how many controls to display based on a value, such as when a user enters 5, you need to display 5 TextBox controls on the form, so the requirement should be implemented using a method that generates HTML tags directly in the background, because if you choose server Controls, There may be more problems to be solved in the development process instead.

Also, large web sites, such as portals, large data forums, community sites, etc., should avoid the use of server controls, because such a large number of Web site access, has been a large server pressure, if you continue to use server controls, but also to increase the cost of the server, which will affect site performance, not only to avoid using server control , but also to do a good job site caching mechanism, page static, etc., reduce the pressure on the service side.

Finally, there is no need to use the server control in fact, there is no hard rules, but to combine the nature of the site to choose a more appropriate method. A good ASP. NET programmer is not only to support the control is so simple, and not what the control is not so extreme, but will be based on the need to choose a suitable implementation method to achieve the desired results.

Use of server controls and HTML controls in ASP.

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.