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 110343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:12:43+00:00 2026-05-11T02:12:43+00:00

I have a base UserControl (BaseControl.cs) which has an OK and Cancel buttons on

  • 0

I have a base UserControl (BaseControl.cs) which has an OK and Cancel buttons on it. When the buttons are clicked, an event is fired. Typically other UserControl objects inherit from the BaseControl. Finally the descendant UserControl objects are placed on a WinForm, where they hook into the events for clicking Ok/Cancel buttons.

My question is this: in the descendant control, I’d like to intercept the events (to run some validation). How can hook into (or intercept) the these events?

Thanks.

  • 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. 2026-05-11T02:12:44+00:00Added an answer on May 11, 2026 at 2:12 am

    The standard pattern for implementing events is to use a virtual ‘OnXxx’ method, like this:

    public event EventHandler OkClick; protected virtual void OnOkClick(EventArgs e) {     if (OkClick != null) OkClick(this, e); } 

    Now any time your base control wants to fire the ‘OkClick’ event, it simply calls:

    OnOkClick(EventArgs.Empty); 

    This means that descendants of your base control can override OnOkClick like this:

    protected override void OnOkClick(EventArgs e) {     // do some stuff before the event is fired     base.OnOkClick(e);     // do some stuff after the event is fired } 

    Note that the framework design guidelines actually state that you should implement the ‘OnXxx’ method in such a way that the event is fired even if the descendant classes forget to call the base method. I don’t really know a good way to do that, and I’m sure most people ignore this guideline.

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

Sidebar

Related Questions

I have a base User Control. I place Ok and Cancel buttons on the
I have a base class object array into which I have typecasted many different
I have a base URL : http://my.server.com/folder/directory/sample And a relative one : ../../other/path How
I have a base page, BasePage, that raises an event that displays messages to
I have a base class with a property which (the get method) I want
I have a base class that has a private static member: class Base {
I have a base class in which I want to specify the methods a
I have an ASP.NET web form that has a container usercontrol that hosts several
I have a UserControl that has some javascript I'd like to inject into a
I have a very weird issue. I have a UserControl that has some controls

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.