{"id":263,"date":"2018-08-06T14:06:32","date_gmt":"2018-08-06T17:06:32","guid":{"rendered":"https:\/\/benjaminray.com\/codebase\/?p=263"},"modified":"2019-02-06T23:56:58","modified_gmt":"2019-02-07T03:56:58","slug":"asp-net-checkbox-click-event-fires-twice","status":"publish","type":"post","link":"https:\/\/benjaminray.com\/codebase\/asp-net-checkbox-click-event-fires-twice\/","title":{"rendered":"ASP.Net Checkbox Click Event Fires Twice"},"content":{"rendered":"<h2>Issue<\/h2>\n<p>When using jQuery to detect and handle the click of an ASP.Net checkbox, the click event is detected twice.  You may notice that the event fires twice<br \/>\nwhen you click on the text of the checkbox, but only once if you click on the actual checkbox input item itself.<\/p>\n<p>It is because the label portion has a \"for\" attribute, and when you click on the label it raises the click event of the input referenced in the \"for\" attribute.<\/p>\n<h2>Solution<\/h2>\n<p>To get around this, add the actual input in the jQuery selector.<\/p>\n<p>Example:<\/p>\n<pre><code>&lt;asp:CheckBox ID=\"chkIncludeNote\" runat=\"server\" CssClass=\"checkbox checkbox-asp check-include-note\" Text=\"Include Note\" \/&gt;\n<\/code><\/pre>\n<pre><code>&lt;script&gt;\n    $(function () {\n        $(document).on('click', '.check-include-note input', function () {\n            \/\/ This only fires once due to the addition of 'input' in the filter above.\n            if ($(this).is(':checked')) {\n                $(this).closest('.modal-body').find('.notes-wrapper').slideUp('fast');\n            } else {\n                $(this).closest('.modal-body').find('.notes-wrapper').slideDown('fast');\n            }\n        });\n    });\n&lt;\/script&gt;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Issue When using jQuery to detect and handle the click of an ASP.Net checkbox, the click event is detected twice. You may notice that the event fires twice when you  [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[13],"tags":[9,2],"class_list":["post-263","post","type-post","status-publish","format-standard","hentry","category-asp-net","tag-asp-net","tag-jquery"],"acf":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9GNjN-4f","jetpack_likes_enabled":false,"_links":{"self":[{"href":"https:\/\/benjaminray.com\/codebase\/wp-json\/wp\/v2\/posts\/263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/benjaminray.com\/codebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/benjaminray.com\/codebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/benjaminray.com\/codebase\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/benjaminray.com\/codebase\/wp-json\/wp\/v2\/comments?post=263"}],"version-history":[{"count":4,"href":"https:\/\/benjaminray.com\/codebase\/wp-json\/wp\/v2\/posts\/263\/revisions"}],"predecessor-version":[{"id":274,"href":"https:\/\/benjaminray.com\/codebase\/wp-json\/wp\/v2\/posts\/263\/revisions\/274"}],"wp:attachment":[{"href":"https:\/\/benjaminray.com\/codebase\/wp-json\/wp\/v2\/media?parent=263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/benjaminray.com\/codebase\/wp-json\/wp\/v2\/categories?post=263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/benjaminray.com\/codebase\/wp-json\/wp\/v2\/tags?post=263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}