Fazil Mir
Fazil Mir

Reputation: 833

Postback is not working?

I have a dropdown in which I am adding list items dynamically. I set autopostback to true, but nothing seems to happen when I select an item in dropdown.

Mark Up

`<asp:DropDownList runat="server" AutoPostBack="true" ID="restaurant_city_con" CssClass="selectboxindex"></asp:DropDownList>`

Code Behind

`if (!this.IsPostBack)
{
    addStates();
    showData();
    dashboardPageFunction();
    ordersPageFunction();
    reportsPageFunction();
    categoriesPageFunction();
    menuPageFunction();
    offersPageFunction();
    bookingPageFunction();
}
else
{
    addCities();
    addZipCode();
}`

Is there anything I am doing wrong ?

Upvotes: 0

Views: 1126

Answers (1)

Karl Anderson
Karl Anderson

Reputation: 34846

You need to handle the OnSelectedIndexChanged event, like this:

Markup:

<asp:DropDownList runat="server" AutoPostBack="true" ID="restaurant_city_con" 
    CssClass="selectboxindex" 
    OnSelectedIndexChanged="restaurant_city_con_SelectedIndexChanged"> 
</asp:DropDownList>

Code-behind:

protected void restaurant_city_con_SelectedIndexChanged(object sender, 
                                                        EventArgs e)
{
    // Do something with selected item here
    Label1.Text = "You selected " + restaurant_city_con.SelectedItem.Text +
                 " with a value of " + restaurant_city_con.SelectedItem.Value +
                 ".";
}

Upvotes: 2

Related Questions