C# 当JQuery选中复选框时,Asp.net复选框OnCheckedChanged未被激发

C# 当JQuery选中复选框时,Asp.net复选框OnCheckedChanged未被激发,c#,jquery,asp.net,events,checkbox,C#,Jquery,Asp.net,Events,Checkbox,感谢您抽出时间阅读和审阅我的帖子。我做了很多谷歌搜索,但还没有找到我的jquery/asp.net问题的答案。我的问题是我试图用一个开/关图像替换标准复选框。关于这一点,有一个简洁的教程。我的问题是,当Jquery在复选框中打勾时,没有调用我的asp OnCheckedChanged复选框事件 有效的ASP.NET母版页脚本 遗言 当JQuery选中复选框时,一切都按需工作,我只是看不到如何让页面自动发布。再次感谢您的帮助 通过javascript所做的更改不会触发诸如onclick或oncha

感谢您抽出时间阅读和审阅我的帖子。我做了很多谷歌搜索,但还没有找到我的jquery/asp.net问题的答案。我的问题是我试图用一个开/关图像替换标准复选框。关于这一点,有一个简洁的教程。我的问题是,当Jquery在复选框中打勾时,没有调用我的asp OnCheckedChanged复选框事件

有效的ASP.NET母版页脚本 遗言
当JQuery选中复选框时,一切都按需工作,我只是看不到如何让页面自动发布。再次感谢您的帮助

通过javascript所做的更改不会触发诸如
onclick
onchange
之类的事件。更改checked的值后,您需要自己触发事件。我不熟悉.net的
OnCheckedChanged
,但是让我们假设在html中它变成
onchange
(您需要通过查看源代码来验证这一点)。您可以这样做:

originalCheckBox.attr('checked', isChecked);
originalCheckBox.change(); // will call the onchange code
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:DetailsView ID="DetailsView1" runat="server" Height="16px" Width="575px">
    <Fields>
        <asp:TemplateField>
            <EditItemTemplate>
                <asp:CheckBox ID="Edit_CheckBox1_CB" runat="server" AutoPostBack="true" OnCheckedChanged="Edit_CheckBox1_CB_Clicked" />
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:CheckBox ID="CheckBox1" runat="server" />
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:CheckBox ID="CheckBox1" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
    </Fields>
</asp:DetailsView>
(function ($) {
$.fn.tzCheckbox = function (options) {

    // Default On / Off labels:

    options = $.extend({
        labels: ['ON', 'OFF']
    }, options);

    return this.each(function () {
        var originalCheckBox = $(this),
            labels = [];

        // Checking for the data-on / data-off HTML5 data attributes:
        if (originalCheckBox.data('on')) {
            labels[0] = originalCheckBox.data('on');
            labels[1] = originalCheckBox.data('off');
        }
        else labels = options.labels;

        // Creating the new checkbox markup:
        var checkBox = $('<span>', {
            className: 'tzCheckBox ' + (this.checked ? 'checked' : ''),
            html: '<span class="tzCBContent">' + labels[this.checked ? 0 : 1] +
                    '</span><span class="tzCBPart"></span>'
        });

        // Inserting the new checkbox, and hiding the original:
        checkBox.insertAfter(originalCheckBox.hide());

        checkBox.click(function () {
            checkBox.toggleClass('checked');

            var isChecked = checkBox.hasClass('checked');

            // Synchronizing the original checkbox:
            originalCheckBox.attr('checked', isChecked);
            checkBox.find('.tzCBContent').html(labels[isChecked ? 0 : 1]);
            if (isChecked) {
               originalCheckBox.attr('checked', isChecked);
            }

        });

        // Listening for changes on the original and affecting the new one:
        originalCheckBox.bind('change', function () {
            checkBox.click();
        });
    });
};
})(jQuery);
.tzCheckBox{
background:url("../Images/background01.png") no-repeat right bottom;
display:inline-block;
min-width:60px;
height:33px;
white-space:nowrap;
position:relative;
cursor:pointer;
margin-left:14px;
}

.tzCheckBox.checked{
background-position:top left;
margin:0 14px 0 0;
}

.tzCheckBox .tzCBContent{
color: white;
line-height: 31px;
padding-right: 38px;
text-align: right;
}

.tzCheckBox.checked .tzCBContent{
text-align:left;
padding:0 0 0 38px;
}

.tzCBPart
{ 
    background:url("../images/background01.png") no-repeat left bottom;
width:14px;
position:absolute;
top:0;
left:-14px;
height:33px;
overflow: hidden;
}

 .tzCheckBox.checked .tzCBPart{
background-position:top right;
left:auto;
right:-14px;
}
originalCheckBox.attr('checked', isChecked);
originalCheckBox.change(); // will call the onchange code