简体   繁体   English

ASP.NET AJAX UpdatePanel下拉列表问题

[英]ASP.NET AJAX UpdatePanel drop down list issue

I have 2 drop-down lists (DDL), and below them an asp.net ajax updatepanel which I want to update/refresh based on selections in the 2 DDL. 我有2个下拉列表(DDL),在它们下面是一个我想根据2个DDL中的选择来更新/刷新的asp.net ajax updatepanel。 The second DDL's contents are dependent on what was selected in the first DDL. 第二个DDL的内容取决于在第一个DDL中选择的内容。

The issue is that if I select something in the first DDL, it doesn't populate the second DDL, but without the ajax updatepanel it works perfectly. 问题是,如果我在第一个DDL中选择了某些内容,它不会填充第二个DDL,但是如果没有ajax updatepanel,它就可以完美地工作。 Please assist if possible. 如果可以的话请协助。 Below is the code. 下面是代码。 Thanks. 谢谢。

<asp:DropDownList runat="server" ID="ddlPrimary" AutoPostBack="true" OnSelectedIndexChanged="ddlPrimary_SelectedIndexChanged"></asp:DropDownList>
<asp:DropDownList runat="server" ID="ddlSecondary" AutoPostBack="true" OnSelectedIndexChanged="ddlSecondary_SelectedIndexChanged"></asp:DropDownList>

<asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="up" runat="server">
    <ContentTemplate>
         <!-- asp.net repeater with table -->
         <tr>
              <td>
                  <asp:Label runat="server" ID="lblProdCode" Text='<%# Eval("ProdCode") %>'></asp:Label>
              </td>
              <td>
                  <asp:Label runat="server" ID="lblProdDesc" Text='<%# Eval("ProdDesc") %>'></asp:Label>
          </tr>
    </ContentTemplate>
    <Triggers>
                <asp:AsyncPostBackTrigger ControlID="ddlPrimary" EventName="SelectedIndexChanged" />
                <asp:AsyncPostBackTrigger ControlID="ddlSecondary" EventName="SelectedIndexChanged" />
     </Triggers>
 </asp:UpdatePanel> 

It will be ok if you move 2 DDL into UpdatePanel and remove trigger tag like this: 如果将2个DDL移到UpdatePanel并删除触发器标记,则可以:

<asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="up" runat="server">
<ContentTemplate>
     <!-- asp.net repeater with table -->
<asp:DropDownList runat="server" ID="ddlPrimary" AutoPostBack="true" OnSelectedIndexChanged="ddlPrimary_SelectedIndexChanged"></asp:DropDownList>
<asp:DropDownList runat="server" ID="ddlSecondary" AutoPostBack="true" OnSelectedIndexChanged="ddlSecondary_SelectedIndexChanged"></asp:DropDownList>

     <tr>
          <td>
              <asp:Label runat="server" ID="lblProdCode" Text='<%# Eval("ProdCode") %>'></asp:Label>
          </td>
          <td>
              <asp:Label runat="server" ID="lblProdDesc" Text='<%# Eval("ProdDesc") %>'></asp:Label>
      </tr>
</ContentTemplate>   

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

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