Mega Code Archive

 
Categories / ASP.Net Tutorial / Page Lifecycle
 

Visualize the current Base64-encoded contents of the view state

<%@ 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>