Control.RenderingCompatibility Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets a value that specifies the ASP.NET version that rendered HTML will be compatible with.
public:
virtual property Version ^ RenderingCompatibility { Version ^ get(); void set(Version ^ value); };
[System.ComponentModel.Bindable(false)]
[System.ComponentModel.Browsable(false)]
public virtual Version RenderingCompatibility { get; set; }
[<System.ComponentModel.Bindable(false)>]
[<System.ComponentModel.Browsable(false)>]
member this.RenderingCompatibility : Version with get, set
Public Overridable Property RenderingCompatibility As Version
Property Value
The ASP.NET version that rendered HTML will be compatible with.
- Attributes
Remarks
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
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.
Note
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
.
Applies to
See also
.NET