重新发布复选框更改

时间:2019-04-21 14:31:46

标签: javascript jquery asp.net web

我想在树形视图的复选框更改时发回邮件,我搜索并找到了答案,但是它不起作用。当我调试时,它永远不会进入事件功能

这是具有属性OnTreeNodeCheckChanged的树

 <asp:TreeView ShowCheckBoxes="All"  OnTreeNodeCheckChanged ="UnSelectedTree_SelectedNodeChanged" ID="UnSelectedTree" runat="server" CssClass="jstree-node  jstree-open jstree-last">
                                                    </asp:TreeView>

并将此功能用于复选框

   function ClientSideChangeSelection(e) {

        var evnt = ((window.event) ? (event) : (e));
        var chkBox = evnt.srcElement || evnt.target;
       // var chkBox = window.event.srcElement;
        var isChecked;
        var isCheckBox = false;

        if (chkBox.tagName == "INPUT" && chkBox.type.toUpperCase() == "CHECKBOX") {
            var treeNode = chkBox;
            isChecked = treeNode.checked;
            do {
                chkBox = chkBox.parentElement;
            } while (chkBox.tagName != "TABLE")
            var firstLevel = chkBox.rows[0].cells.length;

            var tableElements = chkBox.parentElement.getElementsByTagName("TABLE");
            var tableElementsCount = tableElements.length;
            if (tableElementsCount > 0) {
                for (i = 0; i < tableElementsCount; i++) {
                    if (tableElements[i] == chkBox) {
                        i++;
                        isCheckBox = true;
                        if (i == tableElementsCount) {
                            return;
                        }
                    }
                    if (isCheckBox == true) {
                        var secondLevel = tableElements[i].rows[0].cells.length;
                        if (secondLevel > firstLevel) {
                            var cell = tableElements[i].rows[0].cells[secondLevel - 1];
                            var inputElement = cell.getElementsByTagName("INPUT");
                            inputElement[0].checked = isChecked;
                        }
                        else {
                            return;
                        }
                    }
                }
            }
                __doPostBack("", "");
        }

最后这是我的C#代码

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                UnSelectedTree.Attributes.Add("onclick", "ClientSideChangeSelection(event)");
            }
    } 



protected void UnSelectedTree_SelectedNodeChanged(object sender, TreeNodeEventArgs e){
}

0 个答案:

没有答案