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

  • SEARCH
  • Home
  • 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 7743649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:35:19+00:00 2026-06-01T09:35:19+00:00

I have an InfoPath form which I need to conditionally disable it’s OnChange events.

  • 0

I have an InfoPath form which I need to conditionally disable it’s OnChange events. Since it’s not possible to bind the event handlers after the form has loaded, I’m forced to rely on a global counter which indicates whether an OnChange event should be executed.
Inside each OnChange event, I check whether SuppressEventsCount == 0 before performing any actions.
To suppress events during the execution of some function or another, I simply set SuppressEventsCount++, and — again when the function exits. The biggest problem with doing this is that it’s not exception safe. So I had the bright idea to wrap the SuppressEvents counter in a class which implements iDisposable

using(SuppressEvents s = new SuppressEvents()){
   // OnChange events fired here are ignored
} // OnChange events enabled again

This is working, but it’s still not as ideal as a c++ solution which doesn’t require the use of the “using” directive at all.

Is there some way to either:

  1. Trigger a destructor or some function the moment an object goes out of scope, OR
  2. Prevent the SuppressEvents object from being initialised outside of a “using” directive entirely
  • 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-06-01T09:35:21+00:00Added an answer on June 1, 2026 at 9:35 am

    In relation to question 2, it might be possible to get around it by providing a different interface to consumers of the code. Instead of providing a public class that implements IDisposable, and hoping they wrap it in a using, you could provide a static method that takes a function to execute in a “suppressed” context:

    public static class EventSuppressor {
        public void Suppress(Action action) {
            using (var s = new SuppressActions()) {
                action();
            }
        }
    
        private class SuppressActions : IDisposable {
            ...
        }
    }
    

    Then consumers can use this as follows:

    EventSuppressor.Suppress(() => {
        // OnChange events fired here are ignored
    }) // OnChange events enabled again
    

    Of course, you have to work out whether this design is appropriate, as this will result in extra function calls, compiler generated classes and closures etc.

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

Sidebar

Related Questions

I need help getting an infopath form to not overwrite existing files going to
I need to save my InfoPath form regardless of whether the required fields have
Basically I have an InfoPath form which recieves some data from a SharePoint list,
I have an InfoPath form which has two data connections: Connection to a SharePoint
I have a timesheet in a browser-compatible InfoPath 2010 form, which is being submitted
I have an InfoPath form with several fields on, the problem is that one
I have somehow managed to break my infopath form :( When I try to
I have an infopath form template at https://mysite/Shared%20Documents/MyForm.xsn If you click on the xsn
I have an infopath form that I want to modify via jQuery. The only
Scenario I have an InfoPath form. the user fills it in the details, and

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.