How can I disable ViewState for dynamically created controls?
<p>I can't seem to be able to disable ViewState for controls that I add to a page dynamically.</p>

<p><strong>ASPX</strong></p>

<pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Page1.aspx.cs" Inherits="Page1" EnableViewState="false" %&gt;
...
&lt;asp:PlaceHolder ID="DropDownPlaceHolder" runat="server" EnableViewState="false" /&gt;
&lt;asp:Button ID="Submit" runat="server" OnClick="Submit_OnClick" Text="Click Me!"  EnableViewState="false"/&gt;
...
</code></pre>

<p><strong>ASPX.CS</strong></p>

<pre><code>protected override void OnInit(EventArgs e)
{
    DropDownList dropDown = new DropDownList();
    TextBox textBox = new TextBox();

    textBox.EnableViewState = false;

    dropDown.Items.Add("Apple");
    dropDown.Items.Add("Dell");
    dropDown.Items.Add("HP");

    dropDown.AutoPostBack = true;
    dropDown.EnableViewState = false;

    DropDownPlaceHolder.Controls.Add(dropDown);
    DropDownPlaceHolder.Controls.Add(textBox);

    base.OnInit(e);
}
</code></pre>

<p>If I can't disable ViewState on these controls, then I can never programmatically override what a user has entered/selected.</p>

<p>I've tried placing this code in OnInit and Page_Load, but the effect is the same in either location -- ViewState is enabled (the DropDownList maintains selected value and TextBox retains text that was entered).</p>

<p>So, how can I disable ViewState and keep it from populating these controls?</p>

<p>Thanks!</p>

<hr>

<p>Thanks for your response.
Unfortunately, this isn't a workable solution in my situation.</p>

<p>I will be dynamically loading controls based upon a configuration file, and some of those controls will load child controls.</p>

<p>I need to be able to turn the ViewState of controls off individually, without the need to code logic for loading controls in different places (in OnInit vs. LoadComplete
 method).</p>
