Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 60391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:09:16+00:00 2026-05-10T18:09:16+00:00

I can’t seem to be able to disable ViewState for controls that I add

  • 0

I can’t seem to be able to disable ViewState for controls that I add to a page dynamically.

ASPX

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

ASPX.CS

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); } 

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

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).

So, how can I disable ViewState and keep it from populating these controls?

Thanks!


Thanks for your response. Unfortunately, this isn’t a workable solution in my situation.

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

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).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:09:17+00:00Added an answer on May 10, 2026 at 6:09 pm

    It’s a ‘feature’ — http://support.microsoft.com/?id=316813

    Thanks, Microsoft!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
Can somebody point me to a resource that explains how to go about having
Can a LINQ enabled app run on a machine that only has the .NET
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Can anyone help me with an excel formula that groups related rows and creates
Can't seem to get the Back Button to appear in a UINavigationController flow. I
Can we set the alpha of drawable for its disable state through XML? For
can anyone help me in trying to check whether JavaScript is enabled in client
Can 2 or more equations defining a function in Haskell share the same where
can I make my own headers in HTTP request ? e.g. This is normal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.