DropDownList不会在asp:UpdatePanel中触发

时间:2018-03-28 14:10:53

标签: asp.net asynchronous drop-down-menu updatepanel postback

我在asp:UpdatePanel中有一个asp:DropDownList,由于某种原因,从未通过OnSelectedIndexChange方法调用或触发服务器端的方法。我甚至尝试在UpdatePanel上添加一个显式的asp:AsyncPostBackTrigger来试图强制它发生但什么也没发生。当我从UpdatePanel中取出控件时,它将按预期触发OnSelectedIndexChange,但当然它现在刷新整个页面。这是什么问题?这是我的标记:

MARKUP

<asp:ScriptManager ID="SurveyScriptManager" runat="server" />
<div id="container">

    <div class="divSurveyParametersHeaderRow">
        <asp:UpdatePanel runat="server" ID="udpSurveyParameters">
            <ContentTemplate>
                <div id="divFilter">
                    <span><b>Title:</b></span>

                    <asp:DropDownList ID="ddlItems" runat="server" AppendDataBoundItems="true" AutoPostBack="true" OnSelectedIndexChanged="ddlItems_SelectedIndexChanged"
                        ToolTip="Select to add items" DataTextField="LookupItemName" DataValueField="LookupItemId">
                        <asp:ListItem Selected="True" Text="Add..." Value="0"></asp:ListItem>
                    </asp:DropDownList>

                    <asp:CheckBoxList ID="chkFilters" CssClass="chkFilters" runat="server" AutoPostBack="true" RepeatDirection="Horizontal"></asp:CheckBoxList>

                </div>                        
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="ddlItems" EventName="SelectedIndexChanged" />
            </Triggers>
        </asp:UpdatePanel>
    </div>
</div>

代码背后

    protected void Page_Load(object sender, EventArgs e)
    {            
        if (!IsPostBack)
        {
            ddlItems.DataSource = Logic.GetLookupItems();
            ddlItems.DataBind();
        }
    }

    protected void ddlItems_SelectedIndexChanged(object sender, EventArgs e)
    {
        chkFilters.Items.Add(new ListItem { Text = (sender as DropDownList).SelectedItem.Text + "<img src='Resources/delete.png'/>", Value = (sender as DropDownList).SelectedItem.Value });
    }

0 个答案:

没有答案