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 8338811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:42:29+00:00 2026-06-09T04:42:29+00:00

The default.aspx page has a DropDownList which is populated in the code behind only

  • 0

The default.aspx page has a DropDownList which is populated in the code behind only when it is not a postback. When a value is selected a method is called which fills a Literal with the selected value. It works as expected. The problem is when I set the page to not EnableViewState enabling it in the DropDownList control only. In this case when posted back the DropDownList loses its items. I have setup a new Web project just to test this. There is no master page to make it simpler.

Default.aspx:

<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="WebApplication4._Default" 
    EnableViewState="false" %>

<asp:DropDownList ID="DDL" runat="server" 
    OnSelectedIndexChanged="DDL_OSIC" 
    AutoPostBack="true" 
    EnableViewState="true">
</asp:DropDownList>

<asp:Literal ID="Literal1" runat="server"></asp:Literal>

Default.aspx.cs:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        DDL.Items.Add("red");
        DDL.Items.Add("green");
        DDL.Items.Add("blue");
    }
}
protected void DDL_OSIC(object sender, EventArgs e)
{
    Literal1.Text = DDL.SelectedValue;
}

Why isn’t EnableViewState working?

  • 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. Editorial Team
    Editorial Team
    2026-06-09T04:42:30+00:00Added an answer on June 9, 2026 at 4:42 am

    Found the answer with the help of a deleted answer. The deleted answer was wrong just because it was incomplete. With that hint I found the ViewStateMode Property page.

    Summarizing it to disable all controls’ ViewState and enable it just for the choosen ones:

    • Set both the page and all the control’s EnableViewState property to true. This is the default so it is not necessary to write anything
    • Set the page ViewStateMode to Disabled
    • Set ViewStateMode to Enabled in the control where you want ViewState enabled
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Default.aspx, it has it's code behind, Default.cs.aspx. I have a variable
In an ASP.Net WAP, the home page /default.aspx is receiving periodic requests from I-know-not-where.
In my aspx page I have a tr which is set visible=false by default.
I have a div in default.aspx which has a masterpage. Masterpage has a expand/collapse
I have an UpdatePanel in my default.aspx page and the UpdatePanel has asp placeholder,
I have a WebForm before_adm.aspx.cs which has the code as follows: . . .
I have a Default.aspx page in which I have bind a Grid. In the
So here's an interesting conundrum. I have a page, default.aspx. It has a LINK
I have Default.aspx page, which inherits from BasePage.cs, which inherits from System.Web.UI.Page. BasePage is
I have a search.aspx page that has this: <asp:DropDownList id=ddlPopulation runat=server DataTextField=population DataValueField=pid> </asp:DropDownList>

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.