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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:38:52+00:00 2026-06-13T11:38:52+00:00

This seems like a common scenario with an obvious solution, but somehow I haven’t

  • 0

This seems like a common scenario with an obvious solution, but somehow I haven’t encountered it.

I have a DropDownList with an event handler bound to the SelectedIndexChanged event and AutoPostback="true", which works as intended.

The event handler is executed when the value has changed, but if the value is changed via script using jQuery on the client-side, and a post back is subsequently triggered when the user changes the value (and the drop-down’s onchange event fires), then the server-side code detects that the value hasn’t changed since the server last saw its state, and therefore the event handler isn’t run on the server side.

It seems like something that would be loaded via view state, but disabling ViewState has no effect.

  1. The page renders the drop-down with the value “A” selected.
  2. The user changes the drop-down list to value “B”.
  3. The value is automatically posted to the server, and the SelectedIndexChanged event handler is executed.
  4. A client script is run to change the value on the client back to “A” using jQuery.val().
  5. The user changes the value back to “B”.
  6. The value is automatically posted to the server, but because the value was “B” when the server last rendered the page, the SelectedIndexChanged event handler is not executed.

Client-side

<asp:DropDownList ID="dlst" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dlst_SelectedIndexChanged">
    <asp:ListItem Text="A" Value="A" />
    <asp:ListItem Text="B" Value="B" />
</asp:DropDownList>

<asp:Button ID="btnChange" runat="server" Text="Change" OnClientClick="return changeDDL(this,event)" />
<script type="text/javascript">
    function changeDDL(sender, e) {
        var dlst = $("#<%= dlst.ClientID %>");
        dlst.val(dlst.val() === "A" ? "B" : "A");
        return false;
    }
</script>

Server-side

protected void dlst_SelectedIndexChanged(object sender, EventArgs e)
{
    btnChange.Text = dlst.SelectedValue == "A" ? "Change B" : "Change A";
}
  • 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-13T11:38:53+00:00Added an answer on June 13, 2026 at 11:38 am

    After debugging the .Net Framework Reference Source, I’ve concluded the problem is deep in the DropDownList implementation, and can’t be remedied without reimplementing or inheriting the class to change the behavior.

    In the DropDownList class, there is a LoadPostData() implementation of the IPostBackDataHandler interface method.

    Inside LoadPostData(), the index of the value currently selected in the drop-down is compared against the SelectedIndex property that is either loaded from ViewState or defaulted to 0 when EnableViewState="false" is set on the drop-down.

    The OnSelectedIndexChanged() method is called by the RaisePostDataChangedEvent(), which, as the name indicates, is only called if the post data has changed in comparison to the viewstate/default data. Therefore, if the currently selected index matches the viewstate/default index, the SelectedIndexChanged event doesn’t fire.

    In my case, two things can cause the issue:

    1. With ViewState enabled, the current index value matches the SelectedIndex value loaded from ViewState, so SelectedIndexChanged doesn’t fire.
    2. With ViewState disabled, the SelectedIndex value is defaulted to 0, so when the current index value is 0, SelectedIndexChanged doesn’t fire.

    DropDownList.LoadPostData()

    protected virtual bool LoadPostData(String postDataKey, NameValueCollection postCollection) { 
        //{snip...}
        int n = Items.FindByValueInternal(selectedItems[0], false);
    
        if (SelectedIndex != n) {
            SetPostDataSelection(n); // Calls ListControl.SetPostDataSelection() and sets Items[selectedIndex].Selected = true;
            return true;
        } 
    
        return false; 
    }
    

    Later, when the Page class is going through the controls whose post data has changed, the drop-down’s OnSelectedIndexChanged method is called if a change was detected. Since the drop-down’s post data hasn’t changed in this case, the event isn’t raised.

    DropDownList.RaisePostDataChangedEvent()

    protected virtual void RaisePostDataChangedEvent() { 
        //{snip...}
        OnSelectedIndexChanged(EventArgs.Empty); 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems to be like a common use case... but somehow I cannot get
This seems like a common problem, but I'm unable find an adequate solution. I'm
This seems like it would be a common issue to be but I don't
This seems like such a simple issue but I cannot find an elegant solution.
This seems like a must have form input for a mobile ui framework, but
This seems like I'm missing something obvious but I can't get redirects (>) to
I think this is a pretty common scenario, but I haven't been able to
This seems like the most common relationship but for some reason I cannot get
This seems like a common CSS question, but for some reason I cannot find
This seems like a repeated question but i'm not able to get my answer.

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.