Since ASP. NET 1.0, Web forms have become the core functions of ASP. NET. ASP. NET 4 has made many improvements in this regard, for example:
You can set the meta tag.
Enhance view Status control.
Supports recently introduced browsers and devices.
You can use the functions of the browser more easily.
Supports ASP. NET routing for Web forms.
Enhance control over generated IDs.
You can retain the selected row in the Data Control.
Enhance the control of HTML displayed in FormView and ListView controls.
Supports filtering data source controls.
1. Set the meta tag using the Page. MetaKeywords and Page. metadegion attributes.
The Page class adds two attributes: MetaKeywords and metadeworkflow. These two attributes represent the meta tag in HTML. The following is an example:
<Head id = "Head1" runat = "server">
<Title> Untitled Page </title>
<Meta name = "keywords" content = "keyword1, keyword2 '/>
<Meta name = "description" content = "Description of my page"/>
</Head>
These two attributes work in a similar way as the Title attribute. You can set them in the @ Page command.
2. Enable view status for each control
The Control class adds a new attribute: ViewStateMode. This attribute allows you to disable view States for all controls that do not explicitly enable view states on the page. View status data is included in the HTML of the page,
If the view status data is included in the HTML of the page, the request and response time of the page will be extended. Storing excessive view statuses can significantly reduce performance. In earlier versions of ASP. NET, you can disable the view status of a specific control to reduce the impact of view status on page performance. However, it is easier to enable this status for a few controls that require a view status than for controls that do not require a view status.
3. Support for recently introduced browsers and devices
ASP. NET contains a function named "browser feature" that can be used to determine the features of the browser used by users. The Browser function is represented by the HttpBrowserCapabilities object stored in the HttpRequest. Browser attribute. Information about specific browser functions is defined by the browser definition file. In ASP. NET 4, these browser definition files have been updated to include information about recently introduced browsers and devices (such as Google Chrome, Research in Motion BlackBerry smartphones and Apple iPhone. The existing browser definition file has also been updated.
The following list shows the browser definition files attached to ASP. NET 4:
Blackberry. browser
Chrome. browser
Default. browser
Firefox. browser
Gateway. browser
Generic. browser
Ie. browser
Iemobile. browser
Iphone. browser
Opera. browser
Safari. browser
4. define new methods of browser Functions
ASP. NET 4 contains a new feature called "browser function provider. As the name suggests, this function can be used to build a provider that can also be used to write custom code to determine the browser functionality.
In Service Pack 1 of ASP. NET 3.5, You need to define the browser function in an XML file. The file is located in a computer-level folder or application-level folder. Most developers do not need to customize these files, but for those who need them, using the provider method is easier than processing complicated XML syntax. The process can be simplified through the provider method. The method is to implement a general browser definition syntax or a database containing the latest browser definition, or even a Web Service for such a database.
5. routes in ASP. NET 4
ASP. NET 4 provides built-in support for routing using Web forms. Routing is a feature introduced by ASP. NET 3.5 SP1. With this feature, you can configure applications to use URLs that are meaningful to users and search engines, so that you do not need to specify physical file names. With this feature, you can improve site user friendliness and increase the probability that site content is found by search engines.
For example, the following example shows the URL of a page in the product category of an application:
Http: // website/products. aspx? Categoryid = 12
With the routing function, you can use the following URL to display the same information:
Http: // website/products/software
The second URL enables users to understand what they will get and significantly improve their ranking in search engine search results.
New features include:
PageRouteHandler class is a simple HTTP handler used to define a route. You no longer need to write custom route handlers.
The HttpRequest. RequestContext and Page. RouteData attributes allow you to conveniently access the information transmitted in URL parameters.
The RouteParameter class is used to transmit the URL parameter value to the query of the data source control (similar to FormParameter ).
You no longer need to change the Web. config file to enable routing.
6. Set the Client ID
The ClientDMode attribute added to the server control allows you to easily compile client scripts that reference the HTML elements presented by the server control. As Microsoft Ajax is increasingly used, more and more operations are required. For example, you can have a data control that presents a long product price list and want to use a client script to call and update a Web service when the price varies, instead of refreshing the entire page.
Generally, you can use the document. GetElementById method to reference HTML elements in the client script. You need to pass the id attribute value of the referenced HTML element to this method. For elements rendered by ASP. NET Server controls, earlier versions of ASP. NET may be difficult to implement the above operations. It is not always possible to predict that ASP. NET will generate an id value, and ASP. NET may also generate a long id value.
ASP. NET 4 adds two new algorithms used to generate the id feature. These algorithms can generate IDS of easy-to-use client scripts, because they are more predictable and easier to use because they are more concise.
7. Keep row selection in the Data Control
When using the GridView and ListView controls, you can select a row. In earlier versions of ASP. NET, row selection is based on the row index of the page. For example, if you select the third item on page 1 and move it to page 2, the third item on page 2 is selected. In most cases, it is better not to select any row on page 2. ASP. NET 4 supports persistent selection. This new feature was initially provided only in Dynamic Data projects in. NET Framework 3.5 SP1. When this feature is enabled, the item is selected based on the row data key. This means that if you select the third line on page 1 and move it to page 2, no content on page 2 will be set first. When you move back to page 1, the third row is still selected. This behavior is more natural than the behavior in earlier versions of ASP. NET. Currently, the GridView and ListView controls in all projects support persistent selection. For example, you can enable this function by setting the EnablePersistedSelection attribute in the GridView control, as shown in the following example:
<Asp: GridView id = "GridView2" runat = "server" PersistedSelection = "true">
</Asp: GridView>
8. Enhanced Functions of the FormView Control
ASP. NET 4 improved the ForumView control and simplified the style settings of the control content using CSS. In earlier versions of ASP. NET, The FormView control uses the item template to present the content. This makes it very difficult to set the style in the tag, because the control will display unexpected table rows and table cell tags. The FormView control supports the RenderOuterTable attribute in ASP. NET 4. When this attribute is set to false (as shown in the following example), the table tag is not displayed. This makes it easier to apply CSS styles to the control content.
<asp:FormView ID="FormView1" runat="server" RenderTable="false">
9. ListView control enhancement
The ListView control introduced in ASP. NET 3.5 has all the functions of the GridView control, while allowing you to fully control the output. ASP. NET 4 simplifies the use of this control. Earlier versions of the control require you to specify a layout template, which contains a server control with a known ID. The following tag shows a typical example of using the ListView control in ASP. NET 3.5.
<asp:ListView ID="ListView1" runat="server">
<LayoutTemplate>
<asp:PlaceHolder ID="ItemPlaceHolder" runat="server"></asp:PlaceHolder>
</LayoutTemplate>
<ItemTemplate>
<% Eval("LastName")%>
</ItemTemplate>
</asp:ListView>
In ASP. NET 4, The ListView control does not require layout templates. The tag in the preceding example can be replaced with the following tag:
<asp:ListView ID="ListView1" runat="server">
<ItemTemplate>
<% Eval("LastName")%>
</ItemTemplate>
</asp:ListView>
10. Use the QueryExtender control to filter data
A common task for developers who create data-driven web pages is to filter data. The traditional method of executing this task is to generate a Where clause in the data source control. This method may be very complex, and in some cases, the full functionality of the basic database cannot be fully utilized through the Where syntax.
To simplify filtering, ASP. NET 4 adds a new QueryExtender control. You can add this control to the EntityDataSource or LinqDataSource control to filter the data returned by these controls. The QueryExtender control depends on LINQ, but you can use this query extension without having to know how to write a LINQ query.
The QueryExtender control supports multiple filtering options. The following table lists the filter options of QueryExtender.
Terms |
Definition |
SearchExpression |
Search for the string values in one or more fields and compare these values with the specified string values. |
RangeExpression |
Search for values in the range specified by a pair of values in one or more fields. |
PropertyExpression |
Compare the specified value with the attribute value in the field. If the expression returns true, the data to be checked is returned. |
OrderByExpression |
Sort data by specified columns and sorting directions. |
CustomExpression |
Call a function to define the custom filter on the page. |