简体   繁体   English

回发不起作用?

[英]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. 我将autopostback设置为true,但是当我在下拉列表中选择一个项目时,似乎没有任何事情发生。

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 ? 有什么我做错了吗?

You need to handle the OnSelectedIndexChanged event, like this: 您需要处理OnSelectedIndexChanged事件,如下所示:

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 +
                 ".";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM