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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:54:55+00:00 2026-05-23T17:54:55+00:00

I have a dropdownlist that triggers autopostback and fires the SelectedIndexChanged change event. Ive

  • 0

I have a dropdownlist that triggers autopostback and fires the SelectedIndexChanged change event. Ive set viewstate to true but for some reason the selected value is not persisted between postbacks. Ive used the dropdownlist hundreds of times but cant seem to work out why this is happening. The items in the dropdownlist are declaratively coded e.g

<asp:DropDownList ID="SitePrefDropDownList" runat="server" AutoPostBack="True" 
onselectedindexchanged="SitePrefDropDownList_SelectedIndexChanged" EnableViewState="true">
    <asp:ListItem Value="Proffesional">Proffesional</asp:ListItem>
    <asp:ListItem Value="Colorful">Colorful</asp:ListItem>
</asp:DropDownList> 

Any ideas. Im stumped

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Proffesional.master" AutoEventWireup="true" EnableViewState="true"
CodeFile="Home.aspx.cs" Inherits="_Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Label ID="Label1" runat="server" Text="User Name: "></asp:Label>
<asp:TextBox ID="UserNameTextBox" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Color Scheme: ">
</asp:Label><asp:DropDownList ID="SitePrefDropDownList" runat="server" 
AutoPostBack="True" 
onselectedindexchanged="SitePrefDropDownList_SelectedIndexChanged" EnableViewState="true">
    <asp:ListItem Value="Proffesional">Proffesional</asp:ListItem>
    <asp:ListItem Value="Colorful">Colorful</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:Button ID="OKButton" runat="server" Text="OK" onclick="OKButton_Click" />
</asp:Content>

heres the code behind

 public partial class _Default : System.Web.UI.Page
{
protected void Page_PreInit(object sender, EventArgs e) {
    if (Session["Template"] != null) {
        string MasterPage = String.Format("~/{0}.master", (string)Session["Template"]);
        MasterPageFile = MasterPage;
    }
}

protected void Page_Load(object sender, EventArgs e){
}

protected void OKButton_Click(object sender, EventArgs e) {
    if (UserNameTextBox.Text.Length != 0) {
        Session["UserName"] = UserNameTextBox.Text;
        Label Welcome = (Label)Master.FindControl("GreetingLabel");
        Welcome.Text = String.Format("Welcome, {0}!", Session["UserName"]);
    }
}

protected void SitePrefDropDownList_SelectedIndexChanged(object sender, EventArgs e) {
    Session["Template"] = SitePrefDropDownList.SelectedValue;
    Server.Transfer(Request.Path);
}
}
  • 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-05-23T17:54:55+00:00Added an answer on May 23, 2026 at 5:54 pm

    The only reason I can think of, is you are setting some default value in your Page load event.. like..

    protected void Page_Load(object sender, EventArgs e)
    {
        SitePrefDropDownList.SelectedValue = "Proffesional";
    }
    

    Before the SitePrefDropDownList_SelectedIndexChanged event fires in the page life cycle, the Page_load event is called first and your Default/Old value will be reset

    Edit: Your page load should set the value like..

    if (!Page.IsPostback)
    {
       SitePrefDropDownList.SelectedValue = "Proffesional";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DropDownList that fires off some server-side databinding in its OnSelectedIndexChanged event.
I have a dropdownlist that has 4 columns but only 3 are 'visible' the
I have a dropdownlist that has the value of two columns in it... One
I have a DropDownList that contains Station codes. @Html.DropDownList(Station, null, new { id =
i have a dropdownlist that populates from the sql server database. populating the list
I have a dropdownlist that is being populated by a sql server, I am
I have a DropDownList that asks the user if he want to join the
I have an ASP.NET DropDownList control that retrieves the first and last name from
I have a dropdownlist inside a gridview, that is loaded from a datasource when
I have update panel that content check box, textbox, 3 DropDownList with CascadingDropDown extender.

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.