注册JS函数onclick事件时未触发RadioButtonList SelectedIndexChanged事件

时间:2014-07-25 10:20:25

标签: c# asp.net radiobuttonlist server-side-controls

当我单击单选按钮列表控件中的单选按钮时,将调用javascript函数,但服务器端onchange事件不会被触发。我尝试了同样的" onchange"控制事件,但没有工作。

第一种类型 -

<asp:RadioButtonList ID="rdoRightPeriod" runat="server" CssClass="text" 
    OnSelectedIndexChanged="rdoRightPeriod_SelectedIndexChanged" AutoPostBack="true" 
    RepeatDirection="Horizontal" onclick="return showConfirmMessageBoxNew()">
    <asp:ListItem Text="Year Based" Value="Y"></asp:ListItem>
    <asp:ListItem Text="Perpetuity" Value="P"></asp:ListItem>
    <asp:ListItem Text="Run Based" Value="R"></asp:ListItem>
</asp:RadioButtonList>

第二种

<asp:RadioButtonList ID="rdoRightPeriod" runat="server" CssClass="text" 
    OnSelectedIndexChanged="rdoRightPeriod_SelectedIndexChanged" AutoPostBack="true" 
    RepeatDirection="Horizontal">
    <asp:ListItem Text="Year Based" Value="Y" onclick="return showConfirmMessageBoxNew()"></asp:ListItem>
    <asp:ListItem Text="Perpetuity" Value="P" onclick="return showConfirmMessageBoxNew()"></asp:ListItem>
    <asp:ListItem Text="Run Based" Value="R"onclick="return showConfirmMessageBoxNew()"></asp:ListItem>
</asp:RadioButtonList>

我尝试了上述两种技术,但服务器端代码没有被调用。

1 个答案:

答案 0 :(得分:0)

使用OnClientClick而不是使用OnClick。

使用OnClientClick,您可以在服务器端事件旁边运行附加客户端脚本。通过使用OnClick事件,您已使用JavaScript替换了服务器事件的调用。