updatePanel未在单选按钮上刷新

本文关键字:刷新 单选按钮 updatePanel | 更新日期: 2023-09-27 18:00:14

单击单选按钮时,我正在尝试填充下拉列表。第一次没问题,但第二次我去第一次,它不起作用。这意味着Quote在加载时可以工作,单击时应用可以工作,但当返回到报价时,ddl不会刷新。有什么想法吗?请温柔一点,新手。

<asp:UpdatePanel ID="updatePanelToggle" runat="server" UpdateMode="always">
    <ContentTemplate>
        <asp:RadioButton ID="radioOn" Checked="true" AutoPostBack="true" runat="server" GroupName="toggle" Text="Quote" OnCheckedChanged="radioOn_CheckedChanged" />
        <asp:RadioButton ID="radioOff" AutoPostBack="true" runat="server" GroupName="toggle" Text="Apply" OnCheckedChanged="radioOff_CheckedChanged" />
        <asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="radioOn" />
        <asp:AsyncPostBackTrigger ControlID="radioOff" />
    </Triggers>
</asp:UpdatePanel>

背后的代码

protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                loadQuoteURLs();
            }
        }
        protected void radioOn_CheckedChanged(object sender, EventArgs e)
        {      
                loadQuoteURLs();
        }
        protected void radioOff_CheckedChanged(object sender, EventArgs e)
        {
            loadApplyURLs();
        }
        protected void loadApplyURLs()
        {
            DropDownList1.Items.Clear();
            DropDownList1.Items.Add("Apply");
        }
        protected void loadQuoteURLs()
        {
            DropDownList1.Items.Clear();
            DropDownList1.Items.Add("Quote");
        }

updatePanel未在单选按钮上刷新

我试过你的代码,运行良好。无论如何,在这种情况下,您不需要指定UpdateMode="always"并设置AsyncPostBackTriggers

<asp:UpdatePanel ID="updatePanelToggle" runat="server">
    <ContentTemplate>
        <asp:RadioButton ID="radioOn" Checked="true" AutoPostBack="true" runat="server" GroupName="toggle"
            Text="Quote" OnCheckedChanged="radioOn_CheckedChanged" />
        <asp:RadioButton ID="radioOff" AutoPostBack="true" runat="server" GroupName="toggle"
            Text="Apply" OnCheckedChanged="radioOff_CheckedChanged" />
        <asp:DropDownList ID="DropDownList1" runat="server">
        </asp:DropDownList>
    </ContentTemplate>
</asp:UpdatePanel>