Control.RenderingCompatibility Control.RenderingCompatibility Control.RenderingCompatibility Control.RenderingCompatibility Property

定義

取得值,這個值會指定將與呈現 HTML 相容的 ASP.NET 版本。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; }
member this.RenderingCompatibility : Version with get, set
Public Overridable Property RenderingCompatibility As Version

屬性值

將與呈現 HTML 相容的 ASP.NET 版本。The ASP.NET version that rendered HTML will be compatible with.

備註

ASP.NET 會將此屬性設定的值controlRenderingCompatibilityVersion屬性的pagesWeb.config 檔案中的項目。ASP.NET sets this property to the value of the controlRenderingCompatibilityVersion attribute of the pages element in the Web.config file. 如果controlRenderingCompatibilityVersionWeb.config 檔案中未設定屬性,預設值為目前的 ASP.NET 版本。If the controlRenderingCompatibilityVersion attribute is not set in the Web.config file, the default value is the current version of ASP.NET.

警告

沒有為此屬性,公用 set 存取子,但 set 存取子支援的.NET Framework 基礎結構,並不是直接從您的程式碼使用。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.

ASP.NET 的每個發行版本可能會以不同的方式呈現 HTML,從較早的版本。Each release of ASP.NET might render HTML differently from earlier releases. 例如,在 ASP.NET 3.5 中,如果IsEnabled屬性Label控制項false,依預設,ASP.NET 會呈現span項目其disabled屬性設定為"disabled"。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". 在 ASP.NET 4 中,根據預設,span項目以階層式樣式表 (CSS) 來呈現class屬性,而非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. 這可讓您指定已停用控制項的外觀,並避免將無效的 HTML 呈現。This lets you specify the disabled appearance of the control and avoids rendering invalid HTML. (在 HTML 4.0 和 XHTML 1.1span元素不支援disabled屬性。)(In HTML 4.0 and XHTML 1.1, the span element does not support the disabled attribute.)

Web 應用程式可能會包含程式碼,就無法正確運作如果 HTML 轉譯變更。A Web application might include code that would not function correctly if HTML rendering changes. 若要避免這個問題,您可以設定controlRenderingCompatibilityVersion屬性的pagesWeb.config 檔案,以指出您想要維護與相容性的較早版本中的項目。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. 例如,如果您設定RenderingCompatibility屬性,以3.5,已停用Label控制項將會呈現disabled屬性並不是 CSS 類別。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.

注意

您可以將此屬性設定為最早版本3.5The earliest version that you can set this property to is 3.5.

為了與舊版相容,當您使用 Visual Studio Web 專案升級至 ASP.NET 4,從較早版本時,Visual Studio 會自動設定controlRenderingCompatibilityVersionWeb.config 檔案中的屬性3.5To 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. 如果您想要呈現 HTML 所使用的演算法,在 ASP.NET 4 中引進的升級的網站時,您可以變更或移除controlRenderingCompatibilityVersion屬性。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.

大部分的情況下,由這個屬性所控制的行為是自動與您沒有檢查RenderingCompatibility程式碼中的屬性。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. 例如,ASP.NET 4 的自訂控制項可能會組成Label控制項和自訂控制項可能會產生改變的 JavaScript 程式碼來指定已停用控制項的外觀aspNetDisabled類別。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. 這適用於預期 ifRenderingCompatibility4.0或更新版本。This will work as expected if RenderingCompatibility is 4.0 or later. 但若要取得相同時生效RenderingCompatibility3.5,自訂控制項的程式碼必須將控制項的CssClass屬性為"aspNetDisabled"時IsEnabled屬性是falseBut 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.

適用於

另請參閱