Visualize the current Base64-encoded contents of the view state : ViewState « Page Lifecycle « ASP.NET Tutorial






<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Try to Break Your Viewstate</title>
</head>

<script language="javascript">
  function ShowViewState()
  {
    var buf = document.forms[0]["__VIEWSTATE"].value;
    var o = document.forms[0]["ViewStateBox"];
    o.value = buf;
  }
  function UpdateViewState()
  {
    var o = document.forms[0]["ViewStateBox"];
    var viewstate = document.forms[0]["__VIEWSTATE"];
    viewstate.value = o.value;
  }
</script>

<body>
     <form id="form1" runat="server">
        <div id="pageContent">
            <input onclick="ShowViewState()" type="button" value="Display View State" style="width:200px" /> 
            <input onclick="UpdateViewState()" type="button" value="Update View State" style="width:200px" />
            
          <h2>Here's Your (Encoded) ViewState</h2>
        <asp:TextBox id="ViewStateBox" runat="server" TextMode="MultiLine" Width="100%" Height="250px"></asp:TextBox>
        <asp:Button id="Button1" runat="server" Text="Post Back..."></asp:Button>
        </div>
    </form>
</body>
</html>








5.21.ViewState
5.21.1.Use ViewState to create a simple counter (C#)
5.21.2.Save string variable to ViewState
5.21.3.Convert.FromBase64String and view state encoding
5.21.4.Use ViewState to store random data
5.21.5.Visualize the current Base64-encoded contents of the view state
5.21.6.Track Your Viewstate