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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:14:59+00:00 2026-05-24T01:14:59+00:00

I develop address control, which contains 2 DropDownLists (for cities and countries) and several

  • 0

I develop address control, which contains 2 DropDownLists (for cities and countries) and several TextBoxes. The second DropDownList DataSource depends on the first DropDownList DataSource.

<fieldset>
 <legend><%=Title%></legend>
  <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <div>
            <label for="<%=ddlCountry.ClientID %>">Country</label>
            <asp:DropDownList runat="server" ID="ddlCountry" 
              DataTextField="Name" DataValueField="Id" 
              DataSource="<%#Facade.Addresses.GetCountries() %>"
              AutoPostBack="true" 
              OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged"
            />
        </div>
        <div>
            <label for="<%=ddlCity.ClientID %>">City</label>
            <asp:DropDownList runat="server" ID="ddlCity" 
                DataTextField="Name"   DataValueField="Name" />
        </div>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="ddlCountry" EventName="SelectedIndexChanged" />
    </Triggers>
</asp:UpdatePanel>
<div>
    <label for="<%=txtStreet.ClientID %>">Street</label>
    <uc:TextBox ID="txtStreet" Text="<%#Address.Street %>" runat="server" />
</div>
<div>
    <label for="<%=txtBlock.ClientID %>">Block</label>
    <uc:TextBox ID="txtBlock" Text="<%#Address.Block %>" runat="server" />
</div>
<div>
</fieldset> 

Code Behind

protected void Page_Init(object sender, EventArgs e)
  {

    ddlCountry.DataBind();
     if (!IsPostBack)
       {
         ddlCity.DataSource = Facade.Addresses.GetCities(countryId);
         ddlCity.DataBind();
      }

}

protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
  {
     ddlCity.DataSource = Facade.Addresses.GetCities(countryId);
     ddlCity.DataBind();
 }

It works good. But if other control on the page causes PostBack, when the SelectedValue in ddlCity sets to the first (default) value.

How do I avoid it?

  • 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-24T01:15:00+00:00Added an answer on May 24, 2026 at 1:15 am

    Move the code on Page_Init to Page_Load and put it inside !IsPostBack

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ddlCountry.DataBind();
            ddlCity.DataSource = Facade.Addresses.GetCities(countryId);
            ddlCity.DataBind();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to develop an asp.net website which gets an address as an input
I need to develop an application where two csv files are compared. The first
I want to develop an application in which i want to display restaurants nearby
I want to develop a library to handle mail client’s address book. And, I
I want to develop a library to handle mail client’s address book. And, I
I'm currently trying to develop a program which stores lots of data, similar to
This is an effort to develop a Android application which enable C2DM Things I
I'm trying to develop a simple WP7 database app which uses Linq2SQL to query
I have a task to develop the application related to address and access the
For many of the sites we develop, we verify the user's email address. Typically

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.