RadioButtonList SelectedIndexChanged event not fired when JS function onclick event is registered

2.1k Views Asked by At

When I click radio buttons in the radio button list control, javascript function gets called, but the server side onchange event doesn't get triggered. I tried the same with "onchange" event of the control but didn't work.

first type -

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

second type

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

I tried both the above techniques, but the server-side code doesn't get called.

1

There are 1 best solutions below

0
On

Instead of using OnClick, use OnClientClick.

Using OnClientClick you ran run addition client side scripts alongside the server side event. By using the OnClick event, you have replaced the call for the server's event with your JavaScript.