Page.EnableViewState 속성

정의

현재 페이지 요청이 끝날 때 페이지가 자신의 뷰 상태 및 자신이 포함하는 서버 컨트롤의 뷰 상태를 유지하는지 여부를 나타내는 값을 가져오거나 설정합니다.

public:
 virtual property bool EnableViewState { bool get(); void set(bool value); };
[System.ComponentModel.Browsable(false)]
public override bool EnableViewState { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.EnableViewState : bool with get, set
Public Overrides Property EnableViewState As Boolean

속성 값

Boolean

페이지가 자신의 뷰 상태를 유지하면 true이고, 그렇지 않으면 false입니다. 기본값은 true입니다.

특성

예제

다음 코드 예제에서는 페이지가 EnableViewState 로드 될 false 때 속성을 설정 합니다. 이렇게 하면 개체의 Page 보기 상태가 비활성화됩니다. 즉, 페이지에 대한 뷰 상태 정보나 페이지에 포함된 컨트롤이 모두 저장되지 않습니다.

중요

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.

public class WebPage : Page
{
   private MyForm myFormObj;
   private Label label1;
   private Label label2;
   private TextBox textBoxObj;
   private Button buttonObj;

   public WebPage()
   {
      Page.Init += new System.EventHandler(Page_Init);
   }

   private void Page_Load(object sender, System.EventArgs e)
   {
      // Comment the following line to maintain page view state.
      Page.EnableViewState = false;
      myFormObj.Method = "post";
      Controls.Add(myFormObj);
      textBoxObj.Text = "Welcome to .NET";

      label1.Text = "Enter a name";
      buttonObj.Text = "ClickMe";
      buttonObj.Click += new EventHandler(Button_Click);
      myFormObj.Controls.Add(label1);
      myFormObj.Controls.Add(textBoxObj);
      myFormObj.Controls.Add(buttonObj);
      myFormObj.Controls.Add(label2);
   }
   private void Button_Click(object sender, EventArgs e)
   {
      String temp = "<br>Name is " + textBoxObj.Text + "<br>";
      temp += "Saved content of previous page is " + ViewState["name"] as String;
      label2.Text = temp;
   }
   protected override void LoadViewState(object viewState)
   {
      if(viewState != null)
         base.LoadViewState(viewState);
   }
   protected override object SaveViewState()
   {
      ViewState["name"] = textBoxObj.Text;
      return base.SaveViewState();
   }
   private void Page_Init(object sender, EventArgs e)
   {
      this.Load += new System.EventHandler(this.Page_Load);

      myFormObj = new MyForm();
      label1 = new Label();
      label2 = new Label();
      textBoxObj = new TextBox();
      buttonObj = new Button();
   }
};
Public Class WebPage
   Inherits System.Web.UI.Page
   Private myFormObj As MyForm
   Private label1 As Label
   Private label2 As Label
   Private textBoxObj As TextBox
   Private buttonObj As Button
   
   Public Sub New()
      AddHandler Page.Init, AddressOf Page_Init
   End Sub
   
   
   Private Sub Page_Load(sender As Object, e As System.EventArgs)
      ' Comment the following line to maintain page view state.
      Page.EnableViewState = false
      myFormObj.Method = "post"
      Controls.Add(myFormObj)
      textBoxObj.Text = "Welcome to .NET"
      
      label1.Text = "Enter a name"
      buttonObj.Text = "ClickMe"
      AddHandler buttonObj.Click, AddressOf Button_Click
      myFormObj.Controls.Add(label1)
      myFormObj.Controls.Add(textBoxObj)
      myFormObj.Controls.Add(buttonObj)
      myFormObj.Controls.Add(label2)
   End Sub
   
   Private Sub Button_Click(sender As Object, e As EventArgs)
      Dim temp As [String] = "<br>Name is " + textBoxObj.Text + "<br>"
      temp += "Saved content of previous page is " + CType(ViewState("name"), String)
      label2.Text = temp
   End Sub
   
   Protected Overrides Sub LoadViewState(viewState As Object)
      If Not (viewState Is Nothing) Then
         MyBase.LoadViewState(viewState)
      End If
   End Sub
   
   Protected Overrides Function SaveViewState() As Object
      ViewState("name") = textBoxObj.Text
      Return MyBase.SaveViewState()
   End Function 'SaveViewState
   
   Private Sub Page_Init(sender As Object, e As EventArgs)
      AddHandler Me.Load, AddressOf Me.Page_Load
      myFormObj = New MyForm()
      label1 = New Label()
      label2 = New Label()
      textBoxObj = New TextBox()
      buttonObj = New Button()
   End Sub
End Class

설명

보기 상태를 사용하지 않도록 설정할 수 있는 이유에 대한 자세한 내용은 다음을 참조하세요 Control.EnableViewState.

있는 false경우에도 EnableViewState 페이지에는 ASP.NET 포스트백을 검색하는 데 사용되는 숨겨진 보기 상태 필드가 포함될 수 있습니다.

적용 대상

추가 정보