Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# asp.net复选框事件未触发_C#_Javascript_Asp.net_Html - Fatal编程技术网

C# asp.net复选框事件未触发

C# asp.net复选框事件未触发,c#,javascript,asp.net,html,C#,Javascript,Asp.net,Html,我在表格上有一个复选框: <asp:CheckBox ID="CheckBox1" runat="server" Visible="true" AutoPostBack="True" oncheckedchanged="CheckBox1_CheckedChanged" /> 它根本没有进入这个事件。我做错了什么 以下是完整的代码: 如何让它触发事件?我会检查以确保您没有阻止事件触发的验证。我看不出代码有任何错误,因此验证是下一个最可能的罪魁祸首 <asp:CheckBox

我在表格上有一个复选框:

<asp:CheckBox ID="CheckBox1" runat="server"
Visible="true" AutoPostBack="True" oncheckedchanged="CheckBox1_CheckedChanged" />
它根本没有进入这个事件。我做错了什么

以下是完整的代码:


如何让它触发事件?

我会检查以确保您没有阻止事件触发的验证。我看不出代码有任何错误,因此验证是下一个最可能的罪魁祸首

<asp:CheckBox ID="CheckBox1" runat="server" CausesValidation="false" ... />

我认为,由于您使用的是niceforms插件,回发没有启动。该插件似乎覆盖了复选框的默认功能

要测试是否存在这种情况,请尝试从表单标记中删除
class=“niceform”
属性

由于smartforms会覆盖onclick事件,所以我认为解决此问题的唯一方法是通过将inputCheck函数替换为以下函数来修改niceforms插件的源代码。我已经测试过了,它对我有效

function inputCheck(el) { //extend Checkboxes
    el.oldClassName = el.className;
    el.dummy = document.createElement('img');
    el.dummy.src = imagesPath + "0.png";
    if (el.checked) { el.dummy.className = "NFCheck NFh"; }
    else { el.dummy.className = "NFCheck"; }
    el.dummy.ref = el;
    if (isIE == false) { el.dummy.style.left = findPosX(el) + 'px'; el.dummy.style.top = findPosY(el) + 'px'; }
    else { el.dummy.style.left = findPosX(el) + 4 + 'px'; el.dummy.style.top = findPosY(el) + 4 + 'px'; }
    el.dummy.onclick = function () {
        //Set the checked state of the checkbox
        this.ref.checked = this.ref.checked ? false : true;
        //Fire the postback
        this.ref.click();
        if (!this.ref.checked) {
            this.ref.checked = true;
            this.className = "NFCheck NFh";
        }
        else {
            this.ref.checked = false;
            this.className = "NFCheck";
        }
    }
    el.onfocus = function () { this.dummy.className += " NFfocused"; }
    el.onblur = function () { this.dummy.className = this.dummy.className.replace(/ NFfocused/g, ""); }
    el.init = function () {
        this.parentNode.insertBefore(this.dummy, this);
        el.className = "NFhidden";
    }
    el.unload = function () {
        this.parentNode.removeChild(this.dummy);
        this.className = this.oldClassName;
    }
}

希望这能有所帮助。

一个建议是将复选框存储在tempcheck框中,并检查tempcheck是否正确。 如果此复选框位于formedit中,则需要在该字段上使用directcast和find控件。 受保护的子ckbCheckBox_CheckedChanged(ByVal发送方作为对象,ByVal e作为System.EventArgs) Dim tempChk As复选框 尝试 tempChk=DirectCast(YourFormView.FindControl(“ckbCheckBox”),复选框) 如果tempChk.Checked=True,则 “做点什么 其他的 做点什么 如果结束

    Catch ex As Exception
        lblErrorMessage.Text = " Error occurred during ckbCheckBox.  Following are the errors: <br> " & ex.ToString
    End Try

End Sub
Catch-ex作为异常
lblErrorMessage.Text=“ckbCheckBox期间发生错误。以下是错误:
”&ex.ToString 结束尝试 端接头
仅当使用值“true”指定Checkbox的AutoPostBack属性时,才会引发Checkbox控件的CheckedChanged事件

必需的字段验证器等。您使用的是.NET的哪个版本?页面上的任何事件是否触发?让我们看看问题可能出在viewstate或postback事件上。@vinay我如何更改viewstate?如果页面中存在javascript错误,您是否使用FireBug或其他javascript调试器进行了检查?@on如果是,我进行了检查,但没有错误。浏览器对代码进行解释后,代码是什么样子?205 206 207@jdavis我很抱歉,但你能告诉我,我将如何把这纳入我的代码没有担心,很乐意帮助。关于发生了什么变化。我删除了onclick覆盖(似乎没有任何负面影响),并添加了注释过的代码行(请参阅:
//设置复选框的选中状态
//启动回发
)。
    Catch ex As Exception
        lblErrorMessage.Text = " Error occurred during ckbCheckBox.  Following are the errors: <br> " & ex.ToString
    End Try

End Sub