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 會將這個屬性設定為 web.config 檔案controlRenderingCompatibilityVersionpages元素的屬性值。ASP.NET sets this property to the value of the controlRenderingCompatibilityVersion attribute of the pages element in the Web.config file. 如果 web.config controlRenderingCompatibilityVersion檔案中未設定此屬性,則預設值為目前的 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.1 中, span元素不disabled支援屬性)。(In HTML 4.0 and XHTML 1.1, the span element does not support the disabled attribute.)

如果 HTML 轉譯變更,Web 應用程式可能會包含無法正常運作的程式碼。A Web application might include code that would not function correctly if HTML rendering changes. 若要避免這個問題,您可以在controlRenderingCompatibilityVersion web.config 檔案中pages設定元素的屬性,以指出您想要維護與哪一個舊版的相容性。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.5disabled停用Label的控制項會呈現屬性,而不會轉譯 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.5為。The earliest version that you can set this property to is 3.5.

若要維持回溯相容性,當您使用 Visual Studio 將 Web 專案從舊版升級至 ASP.NET 4 時,Visual Studio 會自動將controlRenderingCompatibilityVersion web.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. 如果您想要升級的網站使用 ASP.NET 4 引進的演算法來呈現 HTML,您可以變更或移除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控制群組成,而自訂控制項可能會產生aspNetDisabled改變類別的 JavaScript 程式碼,藉以指定控制項的停用外觀。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. 如果RenderingCompatibility為或更新版本, 4.0這會如預期般運作。This will work as expected if RenderingCompatibility is 4.0 or later. 但是,若要RenderingCompatibility在為3.5時取得相同的效果,當IsEnabled屬性為false時,自訂CssClass控制項的程式碼必須將控制項的屬性設定為 "aspNetDisabled"。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.

適用於

另請參閱