Export (0) Print
Expand All

Control.RenderingCompatibility Property

Gets a value that specifies the ASP.NET version that rendered HTML will be compatible with.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)

[BindableAttribute(false)]
[BrowsableAttribute(false)]
public virtual Version RenderingCompatibility { get; set; }

Property Value

Type: System.Version
The ASP.NET version that rendered HTML will be compatible with.

ASP.NET sets this property to the value of the controlRenderingCompatibilityVersion attribute of the pages element in the Web.config file. If the controlRenderingCompatibilityVersion attribute is not set in the Web.config file, the default value is the current version of ASP.NET.

Caution noteCaution

There is a public set accessor for this property, but the set accessor supports the .NET Framework infrastructure and is not intended to be used directly from your code. If you set this value in your code, the effect is unpredictable.

Each release of ASP.NET might render HTML differently from earlier releases. For example, in ASP.NET 3.5, if the IsEnabled property of a Label control is false, by default, ASP.NET renders a span element whose disabled attribute is set to "disabled". In ASP.NET 4, by default, the span element is rendered with a cascading style sheet (CSS) class attribute instead of the disabled attribute. This lets you specify the disabled appearance of the control and avoids rendering invalid HTML. (In HTML 4.0 and XHTML 1.1, the span element does not support the disabled attribute.)

A Web application might include code that would not function correctly if HTML rendering changes. To avoid this problem, you can set the controlRenderingCompatibilityVersion attribute of the pages element in the Web.config file to indicate which earlier version you want to maintain compatibility with. For example, if you set the RenderingCompatibility property to 3.5, a disabled Label control will render a disabled attribute and not a CSS class.

NoteNote

The earliest version that you can set this property to is 3.5.

To maintain backward compatibility, when you use Visual Studio to upgrade a Web project to ASP.NET 4 from an earlier version, Visual Studio automatically sets the controlRenderingCompatibilityVersion attribute in the Web.config file to 3.5. If you want an upgraded Web site to render HTML using the algorithm that was introduced in ASP.NET 4, you can change or remove the controlRenderingCompatibilityVersion attribute.

Most of the time, the behavior controlled by this property is automatic and you do not have to check the RenderingCompatibility property in your code. However, if you are programming a custom control, you might have to include code that alters the control's behavior based on the setting of this property. For example, a custom control for ASP.NET 4 might be composed of Label controls, and the custom control might specify the disabled appearance of the control by generating JavaScript code that alters the aspNetDisabled class. This will work as expected if RenderingCompatibility is 4.0 or later. But to get the same effect when RenderingCompatibility is 3.5, the custom control's code must set the control's CssClass property to "aspNetDisabled" when the IsEnabled property is false.

.NET Framework

Supported in: 4.5, 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft