【问题标题】:Update dropdownlist on a Panel更新面板上的下拉列表
【发布时间】:2013-09-07 19:30:16
【问题描述】:

我在弹出的面板中有两个 dropDownLists。当我更改第一个 dropDownList 中的一个值时,我想用第一个 dropDownList 中选择的值填充第二个 dropDownList。就像我有AutoPostBack = "true" 一样,页面总是在刷新并且弹出窗口消失了。事实上,我只想更新 PopUp 上的面板。

我正在使用AsyncPostBackTrigger。

<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnShowPopup"
            PopupControlID="pnlpopup" CancelControlID="btnCancel" BackgroundCssClass="modalBackground">
    </asp:ModalPopupExtender>
<asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="199px" Width="400px"
        Style="display: none">
        <table width="100%" style="border: Solid 3px #D55500; width: 100%; height: 100%"
            cellpadding="5" cellspacing="0">
            <tr style="background-color: #D55500">
                <td colspan="2" style="height: 10%; color: White; font-weight: bold; font-size: larger"
                    align="center">
                    Insert Product
                </td>
            </tr>

            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <tr>
                        <td align="right" style="width: 45%">
                            Category:
                        </td>
                        <td> 
                            <asp:DropDownList AutoPostBack="true" runat="server" ID="DropDownList1" OnSelectedIndexChanged="dropDownList_Change" />
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            Product:
                        </td>
                        <td>
                            <asp:DropDownList id="DropDownList2" runat="server">
                            </asp:DropDownList>
                        </td>
                    </tr>
                </ContentTemplate>
                <Triggers> 
                    <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" /> 
                </Triggers> 
            </asp:UpdatePanel>
            <tr>
                <td>
                </td>
                <td>
                    <asp:Label ID="popup_modo" runat="server" Visible="false"></asp:Label>
                    <asp:Button ID="btnCommand" CommandName="Update" runat="server" Text="Update" OnClick="btnUpdate_Click" />
                    <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
                </td>
            </tr>
        </table>
    </asp:Panel>

【问题讨论】:

    标签: c# asp.net refresh updatepanel html-select


    【解决方案1】:

    试试这个:

    <asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="199px" Width="400px"
            Style="display: none">
            <table width="100%" style="border: Solid 3px #D55500; width: 100%; height: 100%"
                cellpadding="5" cellspacing="0">
                <tr style="background-color: #D55500">
                    <td colspan="2" style="height: 10%; color: White; font-weight: bold; font-size: larger"
                        align="center">
                        Insert Product
                    </td>
                </tr>
    
    
                        <tr>
                            <td align="right" style="width: 45%">
                                Category:
                            </td>
                            <td> 
                                <asp:DropDownList AutoPostBack="true" runat="server" ID="DropDownList1" OnSelectedIndexChanged="dropDownList_Change" />
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                Product:
                            </td>
                            <td>
    
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                                <asp:DropDownList id="DropDownList2" runat="server">
                                </asp:DropDownList></ContentTemplate>
                    <Triggers> 
                        <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" /> 
                    </Triggers> 
                </asp:UpdatePanel>
                            </td>
                        </tr>
    
                <tr>
                    <td>
                    </td>
                    <td>
                        <asp:Label ID="popup_modo" runat="server" Visible="false"></asp:Label>
                        <asp:Button ID="btnCommand" CommandName="Update" runat="server" Text="Update" OnClick="btnUpdate_Click" />
                        <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
                    </td>
                </tr>
            </table>
        </asp:Panel>
    

    【讨论】:

    • 页面刷新,弹窗消失。你的变化是什么?
    • 嗯...这是解决这个问题的好方法,但问题是他正在刷新整个页面而不仅仅是面板。似乎无法弄清楚为什么。
    • 在内容模板中,您的 html 以 tr 标记开头,因此您的页面正在刷新..tr 始终是 table 或 thead 或 tbody 的子级,而不是 div 的子级
    • @bruno 您的页面在下拉选择的索引更改事件上得到刷新,对吗?
    • 我的页面正在刷新,因为 AutoPostBack="true"
    【解决方案2】:

    我遇到了类似的问题,关键是在我设置 Items 的部分做 Dropdown。当您设置这些 Items 时,它会在页面重新加载后选择第一个(使用自动回发)。

    如果这是你的问题,试试这个:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            fillDropDown();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-09
      • 1970-01-01
      相关资源
      最近更新 更多