簡體   English   中英

注冊JS函數onclick事件時不會觸發RadioButtonList SelectedIndexChanged事件

[英]RadioButtonList SelectedIndexChanged event not fired when JS function onclick event is registered

當我單擊單選按鈕列表控件中的單選按鈕時,將調用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>

我嘗試了上述兩種技術,但是沒有調用服務器端代碼。

代替使用OnClick,使用OnClientClick。

使用OnClientClick,您可以在服務器端事件旁邊運行其他客戶端腳本。 通過使用OnClick事件,您已用JavaScript替換了對服務器事件的調用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM