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

The Archive Base Latest Questions

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

I have small page which has label, DropDownList and a submit button. <div> <asp:label

  • 0

I have small page which has label, DropDownList and a submit button.

<div>     <asp:label id="Message" runat="server"/>         <br />         Which city do you wish to look at on hotels for?<br /><br />         <asp:dropdownlist id="Dropdownlist1" runat="server" EnableViewState="true">         </asp:dropdownlist>         <br /><br /><br /><br />         <input type="Submit" /> </div> 

On form load I am inserting items into the DropDownList and on the button click I am displaying the count of the items in the DropDownList. Here’s the code for that.

if (Page.IsPostBack) { Message.Text = 'You have selected ' + Dropdownlist1.Items.Count.ToString(); } else { Message.Text = 'You have selected ' + Dropdownlist1.Items.Count.ToString(); Dropdownlist1.Items.Add('Madrid'); Dropdownlist1.Items.Add('Chennai'); Dropdownlist1.Items.Add('New York'); }

Here’s the funny part. If I run it directly from the IDE, its working perfectly fine. I get the count as 0 the first time and 3 when I press submit button. I need to run this small code on an existing virtual directory. If I run the same aspx page within that virtual directory, I get count 0 for the for the first time it loads. When I click submit, I get count as 0 and I don’t see any items in the DropDownList, it is getting cleared. I have set ViewState to true so that I remember what was inserted.

I am not sure what difference is there when I run it from IDE and when I run it from another virtual directory. I am fairly new to Asp.Net so I have exhuasted all my options here so to find out how a DropDownList works. Is there a config I am missing here ?.

BTW just FYI, I am facing the same issue when I put the DropDownList in a Wizard Control. When run from IDE it is working fine but when I run from the virtual directory its not getting the selected value neither is it remembering the items in the DropDownList.

According to your code the list only gets populated when it is not a PostBack. Therefore when you click the button the list will be empty.If you dynamically populate the list, the items are not remembered. You must added in each Page_load. The view state will only remember which item was selected.

How it does then remember the items when the page is executed directly from the IDE and not remember when I run from a virtual directory. Is there a view state that I might need to set to get it working. The cache setting also did not do much luck. I enabled Trace info, funny thing again :|, tracing is happening when executed directly from the IDE and not from the virual directory. Question again, the child directory’s web.config should override the parent web.config right?

  • 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:00:16+00:00Added an answer on May 10, 2026 at 6:00 pm

    It sounds like you may have EnableViewState disabled at the page level. Contrary to the other responses, you don’t need to repopulate your lists on PostBack if ViewState is enabled.

    Try adding the EnableViewState=’true’ attribute in your page header.

    I think it is a bug. If EnableViewState=’false’ at the page level, and EnableViewState=’true’ at the control level, ViewState isn’t retained for the control like it should be.

    If you only want to enable ViewState for certain controls, set EnableViewState=’true’ at the page level, and then EnableViewState=’false’ for the controls which you don’t want to retain ViewState for. Backwards, I know, but it’s the only workaround.

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

Sidebar

Ask A Question

Stats

  • Questions 101k
  • Answers 102k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use Margin or Padding, applied to the scope within the… May 11, 2026 at 8:10 pm
  • Editorial Team
    Editorial Team added an answer The last one is correct ({Binding Path=BackgroundCol}) - however, you… May 11, 2026 at 8:10 pm
  • Editorial Team
    Editorial Team added an answer Try this one: $('ul li a').slice(-1).click(function () { // Your… May 11, 2026 at 8:10 pm

Related Questions

I have an asp.net web page written in C#. Using some javascript I popup
I am working on a small widget for BlogEngine.Net. My widget is going to
I am quite new to ICEfaces but already have experience with JSF/Facelets and the
I have built a custom control that has a small amount of JavaScript. The

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.