updatePanel在radiobutton上没有刷新

时间:2013-02-20 15:46:31

标签: c# asp.net radio-button updatepanel

单击单选按钮时,我尝试填充下拉列表。没问题第一次,但第二次我去了最初的一次它不起作用。这意味着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");

        }

1 个答案:

答案 0 :(得分:1)

我已经尝试过您的代码并且运行正常。无论如何,在这种情况下,您无需指定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>