ASP.NET 4.0单选按钮检查变更事件触发一次 [英] ASP.NET 4.0 Radio button checked changed event fires only once

查看:214
本文介绍了ASP.NET 4.0单选按钮检查变更事件触发一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个单选按钮都设置为异步触发的更新面板,问题是,第一次一个被点击的CheckedChanged事件触发,但随后无论哪个单选按钮被点击的事件永远不会再次闪光。

I have two radio buttons both set as async triggers for an update panel and problem is that first time one is clicked the CheckedChanged event fires but then no matter which radio button is clicked the event never fires again.

标记:

<asp:RadioButton ID="rdoDeliveryBilling" runat="server" Checked="true" GroupName="DeliveryAddress" Text="Deliver to this address" AutoPostBack="true" OnCheckedChanged="rdoDelivery_CheckedChanged" />
<asp:RadioButton ID="rdoDeliveryShipping" runat="server" GroupName="DeliveryAddress" Text="Deliver to a different address" AutoPostBack="true" OnCheckedChanged="rdoDelivery_CheckedChanged" />
<asp:UpdatePanel ID="panDeliveryAddress" runat="server">
<ContentTemplate>
    ...delivery details form controls and validators goes here...
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="rdoDeliveryBilling" EventName="CheckedChanged" />
<asp:AsyncPostBackTrigger ControlID="rdoDeliveryShipping" EventName="CheckedChanged" />
</Triggers>
</asp:UpdatePanel>

code:

protected void rdoDelivery_CheckedChanged(object sender, EventArgs e)
{
    ...only code that enables/disables the delivery form controls and validators goes here...
}

我已经设置里面rdoDelivery_CheckedChanged一个断点,它只击中第一次。

I have set a breakpoint inside rdoDelivery_CheckedChanged and it only hits the first time.

任何想法?

推荐答案

查看源(浏览器),ASP.NET只产生一个回功能 __ doPostBack 单选控制哪个都不可能回发。

Looking at the source (in the browser), ASP.NET is only generating a post back function __doPostBack for the RadioButton controls which can possibly postback.

第一个单选控制不能回传(因为它已经被选中),因此在 __ doPostBack 不是产生的。

The first RadioButton control cannot postback (because it is already checked), and as such the __doPostBack is not generated.

一个解决办法是两个单选控件添加到另一个的UpdatePanel ,设置的UpdateMode 始终。这将导致单选按钮进行更新(当它们触发其它的UpdatePanel )添加 __ doPostBack 函数将取消单选

A work around is to add the two RadioButton controls to another UpdatePanel, setting the UpdateMode to Always. This will cause the RadioButtons to be updated (whenever they trigger the other UpdatePanel) adding the __doPostBack function to the deselected RadioButton.

示例

<asp:UpdatePanel ID="UpdatePanelCheckBoxes" runat="server" UpdateMode="Always">
    <ContentTemplate>
        <asp:RadioButton ID="rdoDeliveryBilling" runat="server" Checked="true" GroupName="DeliveryAddress" Text="Deliver to this address" AutoPostBack="true" OnCheckedChanged="rdoDelivery_CheckedChanged" />
        <asp:RadioButton ID="rdoDeliveryShipping" runat="server" GroupName="DeliveryAddress" Text="Deliver to a different address" AutoPostBack="true" OnCheckedChanged="rdoDelivery_CheckedChanged" />            
    </ContentTemplate>
</asp:UpdatePanel>

希望这有助于。

这篇关于ASP.NET 4.0单选按钮检查变更事件触发一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆