Share via

Page.ViewStateEncryptionMode Property


Gets or sets the encryption mode of the view state.

 property System::Web::UI::ViewStateEncryptionMode ViewStateEncryptionMode { System::Web::UI::ViewStateEncryptionMode get(); void set(System::Web::UI::ViewStateEncryptionMode value); };
public System.Web.UI.ViewStateEncryptionMode ViewStateEncryptionMode { get; set; }
member this.ViewStateEncryptionMode : System.Web.UI.ViewStateEncryptionMode with get, set
Public Property ViewStateEncryptionMode As ViewStateEncryptionMode

Property Value

One of the ViewStateEncryptionMode values. The default value is Auto.



The value set is not a member of the ViewStateEncryptionMode enumeration.

The ViewStateEncryptionMode property can be set only in or before the page PreRender phase in the page life cycle.


The ViewStateEncryptionMode property cannot be set in code. It can only be set in the @ Page directive or in the < element of the configuration file. Values set in the @ Page directive override any values set in the configuration file.

The syntax for setting this property in the @ Page directive is as follows:

<%@ Page Language="VB" ViewStateEncryptionMode="Always" %>  
<%@ Page Language="C#" ViewStateEncryptionMode="Always" %>  

The syntax for setting this property in the configuration file is as follows:

  <pages viewStateEncryptionMode="Always" />  
  <pages viewStateEncryptionMode="Always" />  

Custom control developers may wish to check the value of this property in code before saving potentially sensitive data to view state in their control.

Applies to

See also