After Visual Studio 2012 is released online at Microsoft, we can clearly see some new features in ASP. NET web forms 4.5.
Let's take a look at two new features today: strong data controls and bundling.
Strong Data Control
Before a strong data control occurs, when we bind a data control, the foreground usually uses the form of eval or databinder. eval (container. dataitem, "fieldname.
1 <% # Databinder. eval (container. dataitem, " Fieldname " ) %>
2 <% # Eval ( " Fieldname " ) %>
In ASP. NET web forms 4.5, a strong data control is displayed. controls that can bind data in the background have multiple attributes: itemtype.
After the itemtype of the control is specified, you can use the strong type to bind data in the foreground.
Specify itemtype.
Bind data with a strong type.
At that time, it is estimated that there will be a wave of debate over ORM in the garden.
Bundling
Not very good translation, similar to the compressed package of resource files, simply do not translate it.
We know that one of the main ways to optimize web performance is to reduce HTTP requests. For details, see the minimize HTTP requests in yslow.
As a result, CSS Sprite and CSS/JS compression tools are available to minimize HTTP requests.
In the past, there were many third-party frameworks under the. NET Framework. Microsoft also published a Microsoft Ajax minifier, which I once introduced in an article.
This time in ASP. NET web forms 4.5, this function is simply added, and a class called bundle is added.
1 Public Class Bundleconfig
2 {
3 // For more information on bundling, visit Http://go.microsoft.com/fwlink? Linkid = 254726
4 Public Static Void Registerbundles (bundlecollection bundles)
5 {
6 Bundles. Add ( New Scriptbundle ( " ~ /Bundles/webformsjs " ). Include (
7 " ~ /Scripts/webforms. js " ,
8 " ~ /Scripts/webforms/webuivalidation. js " ,
9 " ~ /Scripts/webforms/menustandards. js " ,
10 " ~ /Scripts/webforms/focus. js " ,
11 " ~ /Scripts/webforms/gridview. js " ,
12 " ~ /Scripts/webforms/detailsview. js " ,
13 " ~ /Scripts/webforms/Treeview. js " ,
14 " ~ /Scripts/webforms/webparts. js " ));
15
16 Bundles. Add ( New Scriptbundle ( " ~ /Bundles/jquery " ). Include (
17 " ~ /Scripts/jquery-{version}. js " ));
18
19 Bundles. Add ( New Scriptbundle ( " ~ /Bundles/msajaxjs " ). Include (
20 " ~ /Scripts/webforms/msajax/microsoftajax. js " ,
21 " ~ /Scripts/webforms/msajax/microsoftajaxapplicationservices. js " ,
22 " ~ /Scripts/webforms/msajax/microsoftajaxtimer. js " ,
23 " ~ /Scripts/webforms/msajax/microsoftajaxwebforms. js " ));
24
25 Bundles. Add ( New Stylebundle ( " ~ /Content/themes/base/CSS " ). Include (
26 " ~ /Content/themes/base/jquery.ui.core.css " ,
27 " ~ /Content/themes/base/jquery.ui.resizable.css " ,
28 " ~ /Content/themes/base/jquery.ui.selectable.css " ,
29 " ~ /Content/themes/base/jquery.ui.accordion.css " ,
30 " ~ /Content/themes/base/jquery.ui.autocomplete.css " ,
31 " ~ /Content/themes/base/jquery.ui.button.css " ,
32 " ~ /Content/themes/base/jquery.ui.dialog.css " ,
33 " ~ /Content/themes/base/jquery.ui.slider.css " ,
34 " ~ /Content/themes/base/jquery.ui.tabs.css " ,
35 " ~ /Content/themes/base/jquery.ui.datepicker.css " ,
36 " ~ /Content/themes/base/jquery.ui.progressbar.css " ,
37 " ~ /Content/themes/base/jquery.ui.theme.css " ));
38 }
39 }
Bundle also supports writing CSS compressed file configurations in the config file, making maintenance more convenient. It also supports CDN and file wildcards.
You can register the configuration in application_start.
1 Void Application_start ( Object Sender, eventargs E)
2 {
3 Bundleconfig. registerbundles (bundletable. bundles );
4 }
.
1 <% : Scripts. Render ( " ~ /Bundles/modernizr " ) %>
2 <% : Scripts. Render ( " ~ /Bundles/jquery " ) %>
3 <% : Scripts. Render ( " ~ /Bundles/jqueryui " ) %>
Compare the number of requests before and after compression (image source ).
Before compression and merge.
After compression.
In this way, when this attribute becomes a feature of ASP. NET, we only need to easily configure it to implement the "Reduce the number of HTTP requests" section in the optimization criterion.