ASP. NET 4 new features (3) enhanced Web Standard Support and auxiliary functions

Source: Internet
Author: User
Document directory
  • 1. Used to disable CSS of controls
  • 2. Used to verify the CSS of the control
  • 3. used to hide the css of the field Div Element
  • 4. CSS for the Table, Image, and ImageButton controls
  • 5. CSS for UpdatePanel and UpdateProgress controls
  • 6. eliminate unnecessary External tables
  • 7. layout template of the wizard Control
  • 8. Added HTML format setting options for the CheckBoxList and RadioButtonList controls
  • 9. header and footer elements of the Table Control
  • 10. CSS and aria support for the Menu Control
  • 11. Valid xhtml for the HtmlForm Control
  • 12. Retain backward compatibility in control rendering

Early versions of ASP. NET controls sometimes present tags that do not comply with HTML, XHTML, or auxiliary functional standards. ASP. NET 4 eliminates most of the exceptions.

1. Used to disable CSS of controls

When a control is disabled in ASP. NET 3.5, a disabled attribute is added to the rendered HTML element. For example, the following tag creates a disabled Label control:

<Asp: Label id = "Label1" runat = "server"

Text = "Test" Enabled = "false"/>

In ASP. NET 3.5, the original control settings generate the following HTML:

<Span id = "Label1" disabled = "disabled"> Test </span>

In HTML 4.01, the disabled feature is considered invalid for the span element. It is only valid for input elements because it specifies that these elements cannot be accessed. For only display elements (such as span), browsers usually support a disabled appearance. However, according to the standard of auxiliary functions, webpages dependent on such non-standard behaviors are not reliable.

For elements that are only for display, CSS should be used to specify the disabled visual appearance. Therefore, by default, ASP. NET 4 generates the following HTML for the preceding control settings:

<Span id = "Label1" class = "aspNetDisabled"> Test </span>

You can set the DisabledCssClass attribute to change the default class attribute value when the control is disabled.

2. Used to verify the CSS of the control

In ASP. NET 3.5, verify that the control render the default color red as an inline style. For example, the following tag creates a RequiredFieldValidator control:

<Asp: RequiredFieldValidator ID = "RequiredFieldValidator1" runat = "server" ErrorMessage = "Required Field" ControlToValidate = "RadioButtonList1"/>

ASP. NET 3.5 presents the following HTML for the verification control:

<Span id = "RequiredFieldValidator1"

Style = "color: Red; visibility: hidden;"> RequiredFieldValidator </span>

By default, ASP. NET 4 does not display inline styles that set the color to red. Inline styles are only used to hide or display validators, as shown in the following example:

<Span id = "RequiredFieldValidator1"

Style = "visibility: hidden;"> RequiredFieldValidator </span>

Therefore, ASP. NET 4 does not automatically display the error message in red.

3. used to hide the css of the field Div Element

ASP. NET stores status information using hidden fields, such as view status and control status. These hidden fields are included in the div element. In ASP. NET 3.5, this div element does not have the class attribute or id attribute. Therefore, CSS rules that affect all div elements may inadvertently make the div visible. To avoid this problem, ASP. NET 4 uses a CSS class to present the div element of the hidden field, which can be used to distinguish the div containing the hidden field from other elements. The following example shows the value of the new class:

<Div class = "aspNetHidden">

4. CSS for the Table, Image, and ImageButton controls

By default, in ASP. NET 3.5, some controls set the border attribute of the rendered HTML to zero. The following example shows the HTML generated by the Table control in ASP. NET 3.5:

<Table id = "Table2" border = "0">

The Image control and ImageButton control are also like this. This setting is unnecessary and provides information that should be set in the visual format provided by CSS. Therefore, this attribute is not automatically generated in ASP. NET 4.

5. CSS for UpdatePanel and UpdateProgress controls

In ASP. NET 3.5, the UpdatePanel and UpdateProgress controls do not support the expando attribute. Therefore, CSS classes cannot be set for the HTML elements they are rendered. In ASP. NET 4, these controls have been changed to accept the expando property, as shown in the following example:

<Asp: UpdatePanel runat = "server" class = "myStyle"> </asp: UpdatePanel>

The HTML displayed by this tag is as follows:

<Div id = "ctl00_MainContent_UpdatePanel1" class = "expandoclass"> </div>

6. eliminate unnecessary External tables

In ASP. NET 3.5, the HTML rendered by the following controls is encapsulated in a table element, which is used to apply inline styles to the entire control:

  • FormView
    Login
    PasswordRecovery
    ChangePassword

If you use a template to customize the appearance of these controls, you can specify the CSS style in the tag provided in the template. In this case, no additional external table is required. In ASP. NET 4, you can avoid table rendering by setting the new RenderOuterTable attribute to false.

7. layout template of the wizard Control

In ASP. NET 3.5, the Wizard and CreateUserWizard controls can generate HTML table elements used for visual format settings. In ASP. NET 4, you can use the LayoutTemplate element to specify the layout. In this case, no HTML table element is generated. In the template, you can create a placeholder control to indicate the position of the dynamically inserted item in the control. (This is similar to the template model of the ListView control .)

8. Added HTML format setting options for the CheckBoxList and RadioButtonList controls

ASP. NET 3.5 uses HTML table elements to set the format for output of the CheckBoxList and RadioButtonList controls. To provide an alternative method for setting visual formats without using tables, ASP. NET 4 adds two options for RepeatLayout enumeration:

  • UnorderedList. This option specifies that the ul and li elements are used, instead of the HTML output format settings for the table.

  • OrderedList. This option specifies that the ol and li elements are used instead of the table to set the HTML output format.

9. header and footer elements of the Table Control

In ASP. NET 3.5, you can set the TableSection attribute of the TableHeaderRow class and TableFooterRow class to render thead and tfoot elements. In ASP. NET 4, these attributes are set to the appropriate values by default.

10. CSS and aria support for the Menu Control

In ASP. NET 3.5, the Menu control uses the HTML table element to set the visual format. In some configurations, the Menu control cannot be accessed through the keyboard. ASP. NET 4 solves these problems through the following methods and improves the accessibility:

  • The generated HTML has an unordered list (ul and li elements) structure.

  • Use CSS to set the visual format.

  • The menu supports keyboard access according to the ARIA standard. You can use the arrow keys to navigate to the menu item.

  • The ARIA role and attribute attributes are added to the generated HTML. (Do not directly include the added features in HTML by using JavaScript to prevent the generated HTML from generating tag verification errors .)

The style of the Menu control is displayed in the style block at the top of the page, rather than inline with the HTML element. If you want to use a separate CSS file to modify the Menu style, you can set the new IncludeStyleBlock attribute of the Menu control to false, so that no style block is generated.

11. Valid xhtml for the HtmlForm Control

In ASP. NET 3.5, the HTML form element that appears in the HtmlForm control (marked by <form runat = "server"> implicitly created) has both the name and id attributes. The name must have been deprecated in XHTML 1.1. Therefore, the control does not display the name attribute in ASP. NET 4.

12. Retain backward compatibility in control rendering

The code in the existing ASP. NET Website may assume that the control is rendered as HTML in ASP. NET 3.5. To avoid backward compatibility when you upgrade the site to ASP. NET 4, you can upgrade the site to allow ASP. NET to continue generating HTML in ASP. NET 3.5. Therefore, you can set the controlRenderingCompatibilityVersion attribute of the pages element to "3.5" in the Web. config file of the ASP. NET 4 website, as shown in the following example:

<System. web>
<Pages controlRenderingCompatibilityVersion = "3.5"/>
</System. web>

If the above settings are omitted, the default value will be the same as the target ASP. NET version of the website.

Related Article

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.