Drop down list controls for country state

Discussion in 'ASP.NET 2.0' started by shawn, Jul 24, 2007.

  1. I have three dropdownlists on an aspx page. One is for the country. One is for the state and one is for Canadian provinces.

    Everything works fine with one exception. If I click the back button on my browser the the country doesn't change but the state/canadian province does.

    I.E. I open the page and the country ddl says 'United States' and the state ddl says 'Alabama'
    Then I click the country ddl and change it to 'Canada' and the ddlCanada appears with 'Alberta' showing.
    Then I hit the back button on my browser and the country ddl stays at 'Canada' but the canada ddl goes hidden and the state ddl appears with 'alabama'. So the page shows Canada as the country and the choices for states are United States one.

    Any help for this?

    Here is the page. (I took out most of the countries and states/provinces so people here didn have to page through all of them)


    <%@ Page Language='VB' %>

    <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>

    <script runat='server'>
    Protected Sub ddlCountry_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    Select Case ddlCountry.SelectedItem.Text
    Case Is = 'Canada'
    ddlEventState.Visible = False
    ddlCanada.Visible = True
    Label2.Visible = True
    Case Is = 'United States'
    ddlCanada.Visible = False
    ddlEventState.Visible = True
    Label2.Visible = True
    Case Else
    ddlEventState.Visible = False
    ddlCanada.Visible = False
    Label2.Visible = False
    Label2.Visible = False
    End Select

    SetFocus(ddlCountry)
    End Sub


    </script>

    <html xmlns='http://www.w3.org/1999/xhtml' >
    <head runat='server'>
    <title>Untitled Page</title>
    </head>

    <form id='form1' runat='server'>
    <div>
    <asp:Label ID='Label1' runat='server' Font-Bold='True' Font-Size='Medium' ForeColor='Black'
    Text='Country: ' Width='97px'></asp:Label><asp:DropDownList ID='ddlCountry' runat='server'
    AutoPostBack='True' OnSelectedIndexChanged='ddlCountry_SelectedIndexChanged'
    Style='z-index: 105' TabIndex='4' Width='124px'>
    <asp:ListItem Value='United States'>United States</asp:ListItem>
    <asp:ListItem Value='Canada'>Canada</asp:ListItem>
    <asp:ListItem Value='Germany'>Germany</asp:ListItem>
    <asp:ListItem Value='France'>France</asp:ListItem>
    <asp:ListItem Value='United Kingdom'>United Kingdom</asp:ListItem>
    <asp:ListItem Value='Japan'>Japan</asp:ListItem>
    <asp:ListItem>--</asp:ListItem>
    <asp:ListItem Value='Afghanistan'>Afghanistan</asp:ListItem>
    <asp:ListItem Value='Albania'>Albania</asp:ListItem>
    <asp:ListItem Value='Algeria'>Algeria</asp:ListItem>
    <asp:ListItem Value='American Samoa'>American Samoa</asp:ListItem>
    <asp:ListItem Value='Andorra'>Andorra</asp:ListItem>
    <asp:ListItem Value='Angola'>Angola</asp:ListItem>
    <asp:ListItem Value='Western Sahar'>Western Sahara</asp:ListItem>
    <asp:ListItem Value='Yemen'>Yemen</asp:ListItem>
    <asp:ListItem Value='Yugoslavia'>Yugoslavia</asp:ListItem>
    <asp:ListItem Value='Zambia'>Zambia</asp:ListItem>
    <asp:ListItem Value='Zimbabwe'>Zimbabwe</asp:ListItem>
    </asp:DropDownList><asp:Label ID='Label2' runat='server' Font-Bold='True' Font-Size='Medium'>State / Province:</asp:Label><asp:DropDownList
    ID='ddlCanada' runat='server' Style='z-index: 105' TabIndex='5' Visible='False'>
    <asp:ListItem Selected='True'>Alberta</asp:ListItem>
    <asp:ListItem>British Columbia</asp:ListItem>
    <asp:ListItem>Manitoba</asp:ListItem>
    <asp:ListItem>New Brunswick</asp:ListItem>
    <asp:ListItem>Newfoundland and Labrador</asp:ListItem>
    <asp:ListItem>Northwest Territories</asp:ListItem>
    </asp:DropDownList><asp:DropDownList ID='ddlEventState' runat='server' TabIndex='5'
    Width='124px'>
    <asp:ListItem Selected='True' Value='Alabama'>Alabama</asp:ListItem>
    <asp:ListItem Value='Alaska'>Alaska</asp:ListItem>
    <asp:ListItem Value='Arizona'>Arizona</asp:ListItem>
    <asp:ListItem Value='Arkansas'>Arkansas</asp:ListItem>
    <asp:ListItem Value='California'>California</asp:ListItem>
    <asp:ListItem Value='Wyoming'>Wyoming</asp:ListItem>
    </asp:DropDownList></div>
    </form>
    </body>
    </html>
     
  2. The browser is caching the page, so you should consider setting the cache-control. For example, you could do...

     

Share This Page