繁体   English   中英

asp.net复选框事件未触发

[英]asp.net checkbox event not firing

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

<asp:CheckBox ID="CheckBox1" runat="server"
Visible="true" AutoPostBack="True" oncheckedchanged="CheckBox1_CheckedChanged" />

当我选中或取消选中它时,它不会触发下面的事件。

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
    if (CheckBox1.Checked)
    {
        preContactTextBox.Visible = true;
        prePracticeCodeTextBox.Visible = true;            
    }
    else
    {
        preContactTextBox.Visible = false;
        prePracticeCodeTextBox.Visible = false;            
    }
}

它根本没有进入这个活动。 我做错了什么?

这是完整的代码:

http://pastebin.com/amQURr91

我如何才能解雇它?

仅当复选框的AutoPostBack属性指定值为“true”时,才会引发Checkbox控件的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是true还是false。 如果此复选框位于已形成的位置,那么您需要在该字段上进行直播并查找控件。 受保护的子ckbCheckBox_CheckedChanged(ByVal发送者作为对象,ByVal e As System.EventArgs)Dim tempChk作为CheckBox尝试tempChk = DirectCast(YourFormView.FindControl(“ckbCheckBox”),CheckBox)如果tempChk.Checked = True那么'做其他什么其他做什么结束如果

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

End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM