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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:53:31+00:00 2026-06-16T12:53:31+00:00

The following code is the markup for my page <div id=addnewcontact> <fieldset style=width:70%;> <legend>Add

  • 0

The following code is the markup for my page

<div id="addnewcontact">
    <fieldset style="width:70%;">
        <legend>Add New Contact Form</legend>
        <asp:panel runat="server" ID="custform" cssclass="contactform visible">
        "code removed for brevity"
            <asp:UpdatePanel ID="updtpanlCity" runat="server">
                <ContentTemplate>
                <!-- State dropdown selector area -->
                <asp:DropDownList ID="ddlStates" runat="server" AppendDataBoundItems="True"
                     AutoPostBack="True" CssClass="dropdowns" TabIndex="7" ToolTip="Select a state"
                    OnSelectedIndexChanged="ddlStates_SelectedIndexChanged">

                </asp:DropDownList>
                <asp:RequiredFieldValidator ID="rfvState" runat="server" ErrorMessage="[Required]"
                        ToolTip="Please select a state" ForeColor="#FF3300" ControlToValidate="ddlStates"
                        Display="Dynamic">
                </asp:RequiredFieldValidator>   
                <!-- End of State dropdown selector area -->
                <br /><p class="spacer"></p>
                <asp:DropDownList ID="ddlCity" runat="server" CssClass="dropdowns"
                        BorderColor="Black" BorderStyle="Solid" BorderWidth="2px"
                        TabIndex="8" ToolTip="Select a city here"
                        OnSelectedIndexChanged="ddlCity_SelectedIndexChanged"
                        AppendDataBoundItems="True" AutoPostBack="True">           
                        <asp:ListItem Value="" Text="Select a city"/>
                </asp:DropDownList>
                <br /><p class="spacer"></p>
                <asp:DropDownList ID="ddlPostalCode"  runat="server" TabIndex="9" 
                        CssClass="dropdowns" ToolTip="Select your postal code here."
                        AppendDataBoundItems="True" AutoPostBack="True">      
                        <asp:ListItem Value="" Text="Postal Code"/>
                </asp:DropDownList>&nbsp;&nbsp;
                <br />  

            </ContentTemplate>     
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="ddlStates" EventName="SelectedIndexChanged"/>
                <asp:AsyncPostBackTrigger ControlID="ddlCity" EventName="SelectedIndexChanged"/>
                <asp:AsyncPostBackTrigger ControlID="ddlPostalCode" EventName="SelectedIndexChanged"/>
            </Triggers>
            </asp:UpdatePanel>
            <br />

            <br /><p class="spacer"></p>
            <asp:Button ID="submit" runat="server" Text="Submit" CssClass="buttons" />

        </asp:panel> <%--end of custform panel--%>
    </fieldset>
</div>

On selecting a state from the state dropdown selector, the code should retrieve a list of cities to populate the city dropdown. This was working before but I rebuilt the page as i changed the database structure. The problem is that the msgbox line i put in the event handler is showing that the selection with index 0 is what is always returned from that event, why is that?

Protected Sub ddlStates_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlStates.SelectedIndexChanged
    If IsPostBack Then
        MsgBox("item: " & ddlStates.SelectedItem.ToString() & "    " & "index: " & ddlStates.SelectedIndex.ToString())
        Dim ctx As New enerteckwebEntities()
        'retrieve the list of cities based on state selected
        Dim citylist As List(Of String) = (From c In ctx.ziptaxes Where c.StateID = Convert.ToInt32(ddlStates.SelectedValue) Order By c.City Ascending Select c.City).ToList()
        With ddlCity
            .Items.Clear()
            .DataSource = citylist.Distinct()
            .DataBind()
            .Items.Insert(0, "Select a city")
            .SelectedIndex = 0
        End With
    End If
End Sub

I have autopostback, appenddatabounditems and enableviewstate set to true in the markup

  • 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-16T12:53:32+00:00Added an answer on June 16, 2026 at 12:53 pm

    Here is one thing you can try.

    1. Make sure that databind the States dropdown in the if(!IsPostBack) condition in the page_load method. This ensures that the dropdown is not databound again when the Selected Index change event is fired.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following markup code in my page: <div id=root_img style=width:100%;height:100%> <div id=id_immagine
Following code are HTML markup and JS part of my signup page. I don't
My intent is to override phone theme. By default page markup has following code:
I have ASP.Net code similar to the following (this is inside a FIELDSET): <ol>
I have the following markup / code block in the ASPX file. The binding
Following code is generated by a for loop. <form action=saveresponse.php method=POST name=mainForm> <input class=cbox_yes
following code doesn't work with input: 2 7 add Elly 0888424242 add Elly 0883666666
I have following workflow div on the page is used on users operation request
I'm trying to teach myself CSS and have the following markup: <style type=text/css> #content
I've the following piece of code which works on one page and doesn't work

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.