Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 677231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:01:00+00:00 2026-05-14T01:01:00+00:00

I have a check box and I have subscribed for the CheckedChanged event. The

  • 0

I have a check box and I have subscribed for the CheckedChanged event. The handler does some operations in there. I check and uncheck the checkbox programmatically (ex: chkbx_Name.Checked = true), and the CheckedChanged event gets fired.

I want this event to be fired only when I manually check or uncheck it. Is there any way to avoid firing of this event when i check/uncheck it programmatically?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:01:00+00:00Added an answer on May 14, 2026 at 1:01 am

    unsubscribe the event before you set:

    check1.CheckChanged -= check1_CheckChanged;
    

    then you can programmatically set the value without the checkbox firing its CheckChanged event:

    check1.Checked = true;
    

    then re-subscribe:

    check1.CheckChanged += check1_CheckChanged;
    

    [EDIT: March 29, 2012]

    The problem with Tanvi’s approach is you need to catch all source of manual check or uncheck. Not that there’s too many(it’s only from mouse click and from user pressing spacebar), but you have to consider invoking a refactored event from MouseClick and KeyUp(detecting the spacebar)

    It’s more neat for a CheckBox(any control for that matter) to be agnostic of the source of user input(keyboard, mouse, etc), so for this I will just make the programmatic setting of CheckBox really programmatic. For example, you can wrap the programmatic setting of the property to an extension method:

    static class Helper
    {
        public static void SetCheckProgrammatically(
            this CheckBox c, 
            EventHandler subscribedEvent, bool b)
        {            
            c.CheckedChanged -= subscribedEvent; // unsubscribe
            c.Checked = b;
            c.CheckedChanged += subscribedEvent; // subscribe
        }
    }
    

    Using this approach, your code can respond neatly to both user’s mouse input and keyboard input via one event only, i.e. via CheckChanged. No duplication of code, no need to subscribe to multiple events (e.g. keyboard, checking/unchecking the CheckBox by pressing spacebar)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a check box list in that user can check or uncheck the
As I have check box in gridview if i dont select any one checkbox
I have a check box like this: fiddle <input type=checkbox value=False id=abc> and in
I have a check box where the property ischecked is bounded to another checkbox.
I have my check box control as shown. <ItemTemplate> <asp:CheckBox ID=chkdelete runat=server Text='<%# Bind(OrderNumber)
I have check box in the form with the following values: <input type=checkbox name=role
I have ten check box in the application. if the user press the checkbox
INSERT MODE i have check box in one tr. and another dropdown control in
I have a check box in my registration form like this: <form name=reg id=reg
I have a check box, RequiredFieldValidator and textbox that have editmask extender I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.