Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET 4.0单选按钮已选中更改事件仅触发一次_C#_Asp.net - Fatal编程技术网

C# ASP.NET 4.0单选按钮已选中更改事件仅触发一次

C# ASP.NET 4.0单选按钮已选中更改事件仅触发一次,c#,asp.net,C#,Asp.net,我有两个单选按钮,都设置为更新面板的异步触发器,问题是第一次单击其中一个时,CheckedChanged事件将触发,但无论单击哪个单选按钮,事件都不会再次触发 标记: <asp:RadioButton ID="rdoDeliveryBilling" runat="server" Checked="true" GroupName="DeliveryAddress" Text="Deliver to this address" AutoPostBack="true" OnCheckedChan

我有两个单选按钮,都设置为更新面板的异步触发器,问题是第一次单击其中一个时,CheckedChanged事件将触发,但无论单击哪个单选按钮,事件都不会再次触发

标记:

<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>
我在rdoDelivery_CheckedChanged中设置了一个断点,它只在第一次命中

有什么想法吗?

查看源代码(在浏览器中),ASP.NET仅为
单选按钮
控件生成一个回发函数
\u doPostBack
,该控件可能会回发

第一个
单选按钮
控件无法回发(因为它已被选中),因此不会生成
\u doPostBack

解决方法是将两个
RadioButton
控件添加到另一个
UpdatePanel
,将
UpdateMode
设置为始终。这将导致单选按钮被更新(每当它们触发另一个
UpdatePanel
)并将
\u doPostBack
功能添加到取消选择的
单选按钮中

示例

<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>


希望这有帮助。

谢谢你帮我解决这个问题。我可能会按照您的建议,将单选按钮放在更新面板中,或者我还找到了另一个解决方案来添加缺少的onclick:radiobutton.Attributes.add(“onclick”、“javascript:setTimeout”(“\u doPostBack(\”)&radiobutton.ClientID.Replace”(“,“$”&“\”,“\”),“\”),“\”),“0)”)此解决方案对我不起作用。我的单选按钮已经在更新面板中了。我尝试在各个单选按钮中添加一个更新面板(它们位于页面的不同位置),但无法使其工作。但至少我知道现在的问题是什么。感谢您提供的有用信息。我有两个UpdatePanel,每个组名中都有一个单选按钮,UpdateMode=“Always”解决了我的问题。谢谢你们
<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>