Web Forms has been a core feature in ASP.NET since the release of ASP.NET 1.0. Many enhancements have been in this area for ASP.NET 4, such as the following:
ASP.NET 4 includes a new feature referred to as browser capabilities providers. As the name suggests, this lets you build a provider that in turn lets you write custom code to determine browser capabilities.
In ASP.NET version 3.5 Service Pack 1, you define browser capabilities in an XML file. This file resides in a machine-level folder or an application-level folder. Most developers do not need to customize these files, but for those who do, the provider approach can be easier than dealing with complex XML syntax. The provider approach makes it possible to simplify the process by implementing a common browser definition syntax, or a database that contains up-to-date browser definitions, or even a Web service for such a database.
For more information about the new browser capabilities provider, see the What's New for ASP.NET 4 White Paper.
ASP.NET 4 adds built-in support for routing with Web Forms. Routing is a feature that was introduced with ASP.NET 3.5 SP1 and lets you configure an application to use URLs that are meaningful to users and to search engines because they do not have to specify physical file names. This can make your site more user-friendly and your site content more discoverable by search engines.
For example, the URL for a page that displays product categories in your application might look like the following example:
http://website/products.aspx?categoryid=12
By using routing, you can use the following URL to render the same information:
http://website/products/software
The second URL lets the user know what to expect and can result in significantly improved rankings in search engine results.
the new features include the following:
The PageRouteHandler class is a simple HTTP handler that you use when you define routes. You no longer have to write a custom route handler.
The HttpRequest..::.RequestContext and Page..::.RouteData properties make it easier to access information that is passed in URL parameters.
The RouteParameter class makes it easier to pass URL parameter values to a query for a data source control (similar to FormParameter).
You no longer have to change the Web.config file to enable routing.
For more information about routing, see the following topics:
A very common task for developers who create data-driven Web pages is to filter data. This traditionally has been performed by building Where clauses in data source controls. This approach can be complicated, and in some cases the Where syntax does not let you take advantage of the full functionality of the underlying database.
To make filtering easier, a new QueryExtender control has been added in ASP.NET 4. This control can be added to EntityDataSource or LinqDataSource controls in order to filter the data returned by these controls. Because the QueryExtender control relies on LINQ, but you do not to need to know how to write LINQ queries to use the query extender.
The QueryExtender control supports a variety of filter options. The following lists QueryExtender filter options.
Term | Definition |
|---|
SearchExpression | Searches a field or fields for string values and compares them to a specified string value. |
RangeExpression | Searches a field or fields for values in a range specified by a pair of values. |
PropertyExpression | Compares a specified value to a property value in a field. If the expression evaluates to true, the data that is being examined is returned. |
OrderByExpression | Sorts data by a specified column and sort direction. |
CustomExpression | Calls a function that defines custom filter in the page. |
For more information, see QueryExtenderQueryExtender Web Server Control Overview.
Earlier versions of ASP.NET controls sometimes render markup that does not conform to HTML, XHTML, or accessibility standards. ASP.NET 4 eliminates most of these exceptions.
For details about how the HTML that is rendered by each control meets accessibility standards, see ASP.NET Controls and Accessibility.
CSS for Controls that Can be Disabled
In ASP.NET 3.5, when a control is disabled (see WebControl..::.Enabled), a disabled attribute is added to the rendered HTML element. For example, the following markup creates a Label control that is disabled:
<asp:Label id="Label1" runat="server"
Text="Test" Enabled="false" />
In ASP.NET 3.5, the previous control settings generate the following HTML:
<span id="Label1" disabled="disabled">Test</span>
In HTML 4.01, the disabled attribute is not considered valid on span elements. It is valid only on input elements because it specifies that they cannot be accessed. On display-only elements such as span elements, browsers typically support rendering for a disabled appearance, but a Web page that relies on this non-standard behavior is not robust according to accessibility standards.
For display-only elements, you should use CSS to indicate a disabled visual appearance. Therefore, by default ASP.NET 4 generates the following HTML for the control settings shown previously:
<span id="Label1" class="aspNetDisabled">Test</span>
You can change the value of the class attribute that is rendered by default when a control is disabled by setting the DisabledCssClass property.
CSS for Validation Controls
In ASP.NET 3.5, validation controls render a default color of red as an inline style. For example, the following markup creates a RequiredFieldValidator control:
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Required Field" ControlToValidate="RadioButtonList1" />
ASP.NET 3.5 renders the following HTML for the validator control:
<span id="RequiredFieldValidator1"
style="color:Red;visibility:hidden;">RequiredFieldValidator</span>
By default, ASP.NET 4 does not render an inline style to set the color to red. An inline style is used only to hide or show the validator, as shown in the following example:
<span id="RequiredFieldValidator1"
style"visibility:hidden;">RequiredFieldValidator</span>
Therefore, ASP.NET 4 does not automatically show error messages in red. For information about how to use CSS to specify a visual style for a validation control, see Validating User Input in ASP.NET Web Pages.
CSS for the Hidden Fields Div Element
ASP.NET uses hidden fields to store state information such as view state and control state. These hidden fields are contained by a div element. In ASP.NET 3.5, this div element does not have a class attribute or an id attribute. Therefore, CSS rules that affect all div elements could unintentionally cause this div to be visible. To avoid this problem, ASP.NET 4 renders the div element for hidden fields with a CSS class that you can use to differentiate the hidden fields div from others. The new class value is shown in the following example:
<div class="aspNetHidden">
CSS for the Table, Image, and ImageButton Controls
By default, in ASP.NET 3.5, some controls set the border attribute of rendered HTML to zero (0). The following example shows HTML that is generated by the Table control in ASP.NET 3.5:
<table id="Table2" border="0">
The Image control and the ImageButton control also do this. Because this is not necessary and provides visual formatting information that should be provided by using CSS, the attribute is not generated in ASP.NET 4.
CSS for the UpdatePanel and UpdateProgress Controls
In ASP.NET 3.5, the UpdatePanel and UpdateProgress controls do not support expando attributes. This makes it impossible to set a CSS class on the HTML elements that they render. In ASP.NET 4 these controls have been changed to accept expando attributes, as shown in the following example:
<asp:UpdatePanel runat="server" class="myStyle">
</asp:UpdatePanel>
The following HTML is rendered for this markup:
<div id="ctl00_MainContent_UpdatePanel1" class="expandoclass">
</div>
Eliminating Unnecessary Outer Tables
In ASP.NET 3.5, the HTML that is rendered for the following controls is wrapped in a table element whose purpose is to apply inline styles to the entire control:
If you use templates to customize the appearance of these controls, you can specify CSS styles in the markup that you provide in the templates. In that case, no extra outer table is required. In ASP.NET 4, you can prevent the table from being rendered by setting the new RenderOuterTable property to false.
Layout Templates for Wizard Controls
In ASP.NET 3.5, the Wizard and CreateUserWizard controls generate an HTML table element that is used for visual formatting. In ASP.NET 4 you can use a LayoutTemplate element to specify the layout. If you do this, the HTML table element is not generated. In the template, you create placeholder controls to indicate where items should be dynamically inserted into the control. (This is similar to how the template model for the ListView control works.) For more information, see the Wizard..::.LayoutTemplate property.
New HTML Formatting Options for the CheckBoxList and RadioButtonList Controls
ASP.NET 3.5 uses HTML table elements to format the output for the CheckBoxList and RadioButtonList controls. To provide an alternative that does not use tables for visual formatting, ASP.NET 4 adds two new options to the RepeatLayout enumeration:
UnorderedList. This option causes the HTML output to be formatted by using ul and li elements instead of a table.
OrderedList. This option causes the HTML output to be formatted by using ol and li elements instead of a table.
For examples of HTML that is rendered for the new options, see the RepeatLayout enumeration.
Header and Footer Elements for the Table Control
In ASP.NET 3.5, the Table control can be configured to render thead and tfoot elements by setting the TableSection property of the TableHeaderRow class and the TableFooterRow class. In ASP.NET 4 these properties are set to the appropriate values by default.
CSS and ARIA Support for the Menu Control
In ASP.NET 3.5, the Menu control uses HTML table elements for visual formatting, and in some configurations it is not keyboard-accessible. ASP.NET 4 addresses these problems and improves accessibility in the following ways:
The generated HTML is structured as an unordered list (ul and li elements).
CSS is used for visual formatting.
The menu behaves in accordance with ARIA standards for keyboard access. You can use arrow keys to navigate menu items. (For information about ARIA, see Accessibility in Visual Studio and ASP.NET.)
ARIA role and property attributes are added to the generated HTML. (Attributes are added by using JavaScript instead of included in the HTML, to avoid generating HTML that would cause markup validation errors.)
Styles for the Menu control are rendered in a style block at the top of the page, instead of inline with the rendered HTML elements. If you want to use a separate CSS file so that you can modify the menu styles, you can set the Menu control's new IncludeStyleBlock property to false, in which case the style block is not generated.
Valid XHTML for the HtmlForm Control
In ASP.NET 3.5, the HtmlForm control (which is created implicitly by the <form runat="server"> tag) renders an HTML form element that has both name and id attributes. The name attribute is deprecated in XHTML 1.1. Therefore, this control does not render the name attribute in ASP.NET 4.
Maintaining Backward Compatibility in Control Rendering
An existing ASP.NET Web site might have code in it that assumes that controls are rendering HTML the way they do in ASP.NET 3.5. To avoid causing backward compatibility problems when you upgrade the site to ASP.NET 4, you can have ASP.NET continue to generate HTML the way it does in ASP.NET 3.5 after you upgrade the site. To do so, you can set the controlRenderingCompatibilityVersion attribute of the pages element to "3.5" in the Web.config file of an ASP.NET 4 Web site, as shown in the following example:
<system.web>
<pages controlRenderingCompatibilityVersion="3.5"/>
</system.web>
If this setting is omitted, the default value is the same as the version of ASP.NET that the Web site targets. (For information about multi-targeting in ASP.NET, see .NET Framework Multi-Targeting for ASP.NET Web Projects.)