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

  • Home
  • SEARCH
  • 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 736651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:37:46+00:00 2026-05-14T07:37:46+00:00

i have two select using as a dropdownlist for country/state everything works as i

  • 0

i have two select using as a dropdownlist for country/state

everything works as i expected but when i do a postback then i lost the values from the above <select...> what is the best way to retain the values and can you show me with an example please?

<asp: Button ID="Button1" runat="server" 
onclick="Button1_Click" Text="PostBack" />

thanks.

  • 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-14T07:37:47+00:00Added an answer on May 14, 2026 at 7:37 am

    If you’re using ASP.NET with some jQuery, you could set the value of a hidden field in the post back. Then in the $(document).ready() you just read that value from the hidden field.

    In your code behind:

    protected void Button1_Click(object sender, EventArgs e)
    {
      this.countryField.Value = "WhateverValueYouWantToPersist";
    }
    

    In your aspx file:

    $(document).ready(function(){
      var persistedValue = <% this.countryField.ClientID %>;
      // do something...
    });
    
    <asp:HiddenField runat="server" ID="countryField" />
    

    Update:

    I came up with a little better solution. I hope you only want to capture the selected values form the select lists and don’t need to persist the whole country/state collection.

    I would setup my aspx page as so:

    <asp:DropDownList runat="server" ID="countryField" />
    <asp:DropDownList runat="server" ID="stateField" />
    
    <asp:Button runat="server" ID="button1" OnClick="button1_click" OnClientClick="return clientSideClick()" />
    
    <asp:HiddenField runat="server" ID="hiddenCountry" />
    <asp:HiddenField runat="server" ID="hiddenState" />
    

    In my jQuery i would have a function to handle that click, which captures the selected value(s) and sets the value for the hidden fields:

    function clientSideClick() {
        var state = $("#<%= this.stateField.ClientID %> :selected").val();
        $("#<%= this.hiddenState.ClientID %>").val(state);
    
        var country = $("#<%= this.countryField.ClientID %> :selected").val();
        $("#<%= this.hiddenCountry.ClientID %>").val(country);
    }
    

    Then in your server side button post back event, you could capture the value of the hidden states and do whatever you need to do from there:

    protected void button1_click(object sender, EventArgs e)
    {
        string stateValue = this.hiddenState.Value;
        string countryValue = this.hiddenCountry.Value;
    }
    

    If you did want to re-select the previously selected Country/State pair, then after your jQuery code loads the Countries and States using your ajax routines, the previously selected values will still be in that hidden field and you can use the values from there.

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

Sidebar

Related Questions

i have dropdownlist with the values: <select id=myddl name=myddl> <option value=1>One</option> <option value=2>Twooo</option> <option
I have two <select>s with the same <option>s , and I need - using
I have the following two columns: SELECT b.ip_address AS IP ,b.mask AS MASK FROM
Ok, I have two tables that I am joining and doing a select on
I have tried the following two statements: SELECT col FROM db.tbl WHERE col (LIKE
I have multiple selects: <select id=one> <option value=1>one</option> <option value=2>two</option> <option value=3>three</option> </select> <select
I have two applications written in Java that communicate with each other using XML
I have two dropdownlist which shows places in my asp.net MVC(C#) application. The First
I have two dropdown lists: <asp:DropDownList ID=Field_Type runat=server /> <asp:DropDownList ID=Field_SubType runat=server /> Field_Type
Hello I have two dependants select box, the second one is popularited after onchange

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.