Parry
Source: http://www.cnblogs.com/parry/
A. Strongly typed data Control
When we bind a data control before a strongly typed data control appears, the foreground generally 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, there are strongly typed data controls that can be used to bind data in the background with a single property: ItemType.
When you specify a control's itemtype, you can use strongly typed binding data in the foreground.
Specifies ItemType.
Bind data using strongly typed.
The garden is expected to stir up a debate on the ORM:)
Second, bundling
Not very good translation, similar to the resource file of the compressed package, simply do not translate it.
One of the main ways we know of Web performance optimization is to reduce HTTP requests, and to see the YSlow minimize HTTP requests in detail.
The result is a CSS Sprite, compression Css/js tool, the purpose is to minimize the HTTP request.
Before. NET Framework, there will be a lot of third-party framework, Microsoft also out of a Microsoft Ajax Minifier, I have also been an article introduced.
And this time in ASP. NET Web Forms 4.5, simply add this function directly, a lot of a class called bundle.
1 public class Bundleconfig
2 {
3/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/webforms.js",
8 "~/scripts/webforms/webuivalidation.js",
9 "~/scripts/webforms/menustandards.js",
Ten "~/scripts/webforms/focus.js",
"~/scripts/webforms/gridview.js",
"~/scripts/webforms/detailsview.js",
"~/scripts/webforms/treeview.js",
"~/scripts/webforms/webparts.js"));
15
Bundles. ADD (New Scriptbundle ("~/bundles/jquery"). Include (
"~/scripts/jquery-{version}.js"));
18
Bundles. ADD (New Scriptbundle ("~/bundles/msajaxjs"). Include (
"~/scripts/webforms/msajax/microsoftajax.js",
"~/scripts/webforms/msajax/microsoftajaxapplicationservices.js",
"~/scripts/webforms/msajax/microsoftajaxtimer.js",
"~/scripts/webforms/msajax/microsoftajaxwebforms.js"));
24
Bundles. ADD (New Stylebundle ("~/content/themes/base/css"). Include (
"~/content/themes/base/jquery.ui.core.css",
"~/content/themes/base/jquery.ui.resizable.css",
"~/content/themes/base/jquery.ui.selectable.css",
"~/content/themes/base/jquery.ui.accordion.css",
"~/content/themes/base/jquery.ui.autocomplete.css",
"~/content/themes/base/jquery.ui.button.css",
"~/content/themes/base/jquery.ui.dialog.css",
"~/content/themes/base/jquery.ui.slider.css",
"~/content/themes/base/jquery.ui.tabs.css",
"~/content/themes/base/jquery.ui.datepicker.css",
"~/content/themes/base/jquery.ui.progressbar.css",
Panax Notoginseng "~/content/themes/base/jquery.ui.theme.css"));
38}
39}
Bundle also supports the CSS compressed file configuration written in the config file, making maintenance more convenient, but also support CDN and file wildcard characters.
Can be configured by registering in Application_Start.
1 void Application_Start (object sender, EventArgs e)
2 {
3 Bundleconfig.registerbundles (bundletable.bundles);
4}
Use.
1 <%: Scripts.render ("~/bundles/modernizr")%>
2 <%: Scripts.render ("~/bundles/jquery")%>
3 <%: Scripts.render ("~/bundles/jqueryui")%>
Comparison of requests before and after compression (image source).
Compress before merging.
After compression.
Thus, when this property becomes a feature of the ASP. NET, we only need to configure it very simply to implement the "reduce the number of HTTP requests" in the optimization criteria.
Third, update for the HTML5
in ASP. NET Web Forms 4.5, the TextBoxMode of the control TextBox increased from three (Singleline/multiline/password) to 16, as detailed in MSDN.
This makes the form of the page, the drop will greatly reduce the amount of code validation, improve development efficiency, and more human resources in the business logic.
The FileUpload control finally starts to support multiple file uploads, which can be opened via the AllowMultiple property.
Use the FileUpload class instructions in detail for the MSDN reference.
Of course, it also includes validation of HTML5 forms, HTML5 tags can also use "~" to go to the root directory, increase UpdatePanel support for HTML5 forms.
Iv. unobtrusive Validation
The so-called unobtrusive Validation is an implicit authentication method that separates the validation code from the HTML.
To learn more about its improvements, let's look at how the validation logic is handled before ASP. NET Web Forms 4.5.
We have added this simple input form to the page.
1 <body>
2 <form id= "Form1" runat= "Server" >
3 <div>
4 <ul>
5 <li>
6 <asp:textbox id= "Textbox_number" runat= "Server" textmode= "Singleline" ></asp:TextBox>
7 <asp:requiredfieldvalidator id= "RequiredFieldValidator1" runat= "Server"
8 errormessage= "*required"
9 controltovalidate= "Textbox_number"
Ten enableclientscript= "true" ></asp:RequiredFieldValidator>
<asp:rangevalidator id= "RangeValidator1" runat= "Server"
Controltovalidate= "Textbox_number"
Errormessage= "*range 10~100"
Maximumvalue= "100"
Minimumvalue= "Ten" ></asp:RangeValidator>
</li>
<li>
<asp:button id= "Button1" runat= "Server" text= "Submit"/></li>
</ul>
</div>
</form>
</body>
When we look at the source code generated by the page, we will find something like this.
Background will verify the JS code in the page, and when the page validation logic is very complex, will generate a lot of inline code, in the back of the page to do optimization (such as JS compression, CDN, page compression), maintenance time is very inconvenient.
in ASP. NET Web Forms 4.5, you can detach the validation logic from this class.
You can add a configuration such as the following in Web. config.
1 <appSettings>
2 <!--enable unobtrusive Validation, by default
3 <add key= "Validationsettings:unobtrusivevalidationmode" value= "WebForm"/>
4
5 <!--Close unobtrusive validation-->
6 <!--<add key= "Validationsettings:unobtrusivevalidationmode" value= "None"/>-->
7 </appSettings>
Or add this segment to the Application_Start.
1 void Application_Start (object sender, EventArgs e)
2 {
3//enabling unobtrusivevalidation Application Wide
4 Validationsettings.unobtrusivevalidationmode = unobtrusivevalidationmode.webforms;
5}
And if you just want to control a page to turn on this feature just add this code.
1 page.unobtrusivevalidationmode = System.Web.UI.UnobtrusiveValidationMode.WebForms;
Now let's look at the HTML code generated to the client.
We found that the validation class information has become a form-specific attribute in HTML5 data-*
The inline JS content in the page has been processed, and jquery is automatically introduced for verification, which can be referred to unobtrusive JavaScript.
Five. Model Binding
If you've used the ObjectDataSource control, you're definitely impressed with its selectmethod, and in ASP. NET Web Forms 4.5, Microsoft has moved this method directly to the strongly typed control.
Replace the previous DataBind method directly with a more convenient SelectMethod method, as described here.
The SelectMethod method accepts objects of type IEnumerable or IQueryable, and if you use the ItemType attribute described previously, you will need to accept ienumerable<t> or iqueryable<t > Type of object, T is consistent with the previous itemtype.
Set a GridView configuration as we do.
1 <form id= "Form1" runat= "Server" >
2 <div>
3 <asp:gridview id= "gridview_users" runat= "Server" itemtype= "Modelbinding.users"
4 datakeynames= "UserID" selectmethod= "Getusers"
5 autogeneratecolumns= "False" >
6 <Columns>
7 <asp:boundfield datafield= "UserID" headertext= "User ID"/>
8 <asp:boundfield datafield= "UserName" headertext= "User Name"/>
9 <asp:boundfield datafield= "UserEmail" headertext= "Email"/>
Ten </Columns>
</asp:GridView>
<asp:validationsummary id= "Validationsummary_useredit" runat= "Server" showmodelstateerrors= "true"/>
</div>
</form>
Background binding data.
1 public iqueryable<users> getusers ()
2 {
3 list<users> List = new list<users> ();
4 list. ADD (New Users () {UserID = 1, UserName = "Parry", useremail = "[Email protected]"});
5 list. ADD (New Users () {UserID = 2, UserName = "Spiderman", useremail = "[Email protected]"});
6 list. ADD (New Users () {UserID = 3, UserName = "Superman", useremail = "[Email protected]"});
7 list. ADD (New Users () {UserID = 4, UserName = "Batman", useremail = "[Email protected]"});
8 return list. Asqueryable<users> ();
9}
Page display.
Of course, the controls also support UpdateMethod and DeleteMethod, respectively, for modification and deletion.
It is important to note that parameter properties can also be defined in SelectMethod defined in the background.
Public iqueryable<users> getusers ([Control]int. UserID)
They also support form, QueryString, Cookies, and URL attributes.
The overall feeling this part is that the ASP. NET Web Forms 4.5 has changed a lot and is more like MVC. Microsoft combines the EF, the strongly typed controls, the Model binding, and defines a regular method and process for backing up the bindings.
A more detailed introduction can be found in the SCOTTGU series article: Web Forms Model Binding.
new features for ASP. NET Web Forms 4.5