Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Set the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.viewstatemode.aspx" rel="nofollow"><code>ViewStateMode</code></a> to <code>Disabled</code> on the page, and omit <code>EnableViewState</code>. You can set it to enabled for some controls (default is <code>Inherit</code>).</p> <p><strong>Edit (sidenote, see comments too):</strong></p> <p>As we discussed in the comment, text boxes keep their value even though ViewState is disabled. This is true, as they are elements of a HTTP POST request. Labels aren't, for instance, as they render to <code>span</code> tags.</p> <p>In the following sample code, there is a label filled with a random number. If you set <code>ViewStateMode</code> to <code>Enabled</code>, the random number from the last request is written to the Debug Output Window. If you set <code>ViewStateMode</code> to <code>Disabled</code>, an empty string is written. The <code>Label</code>'s state is not kept:</p> <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2.Default" ViewStateMode="Disabled" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;asp:TextBox runat="server" ID="textbox" Text="Default" /&gt; &lt;asp:Label runat="server" ID="randomNumberLabel" /&gt; &lt;asp:Button runat="server" Text="Click Me" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>This is the code behind. Be sure to attach a debugger:</p> <pre><code>namespace WebApplication2 { public partial class Default : System.Web.UI.Page { private readonly static Random rnd = new Random(); protected void Page_Load(object sender, EventArgs e) { if(this.IsPostBack) Debug.WriteLine(this.randomNumberLabel.Text); this.randomNumberLabel.Text = rnd.Next(Int32.MaxValue).ToString(); } } } </code></pre> <p>I hope I managed to clarify the difference.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload