取消选择后如何用ASP RadioButtonList回发OnSelectedIndexChanged?

时间:2018-08-01 21:24:05

标签: jquery asp.net

我有一个癌症asp(3.5)单选按钮列表,该列表张贴在SelectedIndexChanged上

<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
</head>
<body>

    <h1>Your Friends</h1>
    <div class="mx-auto" style="width: 700;">
        <table id="existingFriends" class="table table-striped table-dark table-hover">
            <thead>
                <tr>
                    <th scope="col">Name</th>
                    <th scope="col">Office</th>
                    <th scope="col">Friend Level</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Dwayne 'The Rock' Johnson</td>
                    <td>Dallas></td>
                    <td>Top Dog/BFF</td>
                </tr>
            </tbody>
        </table>
    </div>
    <h1>Suggested Friends</h1>
    <div class="table-container" style="width:500;" align="center;">
        <table id="addFriends" class="table table-striped table-dark table-hover">
            <thead>
                <tr>
                    <th scope="col">Name</th>
                    <th scope="col">Office</th>
                    <th scope="col">Friend Level</th>
                    <th scope="col">Add</th>
                </tr>
            </thead>
            <tbody>
                <tr id="ryan">
                    <td>Ryan Reynolds</td>
                    <td>Dallas</td>
                    <td>Acquaintance</td>
                    <td class="addColumn">
                        <a role="button" class="btn btn-success btn-sm" value="Shift Row" onclick="shiftFunc(this); putBack();">
                            <i class="fas fa-check-square"></i>
                        </a>
                    </td>
                </tr>
                 <tr id="daniel">
                    <td>Daniel </td>
                    <td>Dallas</td>
                    <td>Acquaintance</td>
                    <td class="addColumn">
                        <a role="button" class="btn btn-success btn-sm" value="Shift Row" onclick="shiftFunc(this); putBack();">
                            <i class="fas fa-check-square"></i>
                        </a>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <script language="javascript">
        var row = document.getElementById("ryan");
        function shiftFunc(elem) {
            row = elem.parentNode.parentNode;
            row.parentNode.removeChild(row);
        }
        function putBack() {
            var tbl = document.getElementById("existingFriends");
            var add = row.querySelector('.addColumn');
            row.removeChild(add);
            tbl.appendChild(row);
        }
    </script>
</body>
</html>

在某一时刻,我使用jQuery取消了单选按钮列表上的所有选择

<asp:RadioButtonList ID="rblSelectQuoteOrSolution" runat="server"  OnSelectedIndexChanged="rblSelectQuoteOrSolution_SelectedIndexChanged" AutoPostBack="true" RepeatDirection="Vertical">
    <asp:ListItem Text="Quote ID" Value="QuoteID"></asp:ListItem>
    <asp:ListItem Text="Solution ID" Value="SolutionID"></asp:ListItem>
    <asp:ListItem Text="Other" Value="Other"></asp:ListItem>
</asp:RadioButtonList>

这是一个问题,因为如果用户在进行了所需的任何更改后又返回到单选按钮列表,并且他们单击了之前选择的同一单选按钮,则OnSelectedIndexChanged事件将不会触发,因为似乎只有客户端才知道RadioButton选择已被清除,服务器端控件认为其仍处于选中状态!

关于即使用户选择了先前选择的单选按钮,如何使单选按钮列表回发到服务器的任何想法?这可能是不可能的。

1 个答案:

答案 0 :(得分:0)

First Fall You have remove AutoPostback=true; In Javascript: $("#rblSelectQuoteOrSolution:checked").on('change',function(){ //Code. })
                       Or
$("input:radio:checked").on('change',function(){ //Code. })