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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:35:14+00:00 2026-05-17T14:35:14+00:00

I created a control where other developers can create an instance and use. There

  • 0

I created a control where other developers can create an instance and use. There is a button click in the control. How do I allow developers to plug in their own code in a certain part of my control? I am not sure if or how exactly to use a delegate or event in this scenario. Can someone help in the below example:

public class MyControl : CompositeControl
{
   ...
   void btnSubmit_Click(object sender, EventArgs e)
   {
      //DO SOMETHING
      if (success)
      {
         //CALL DEVELOPER'S LOGIC
      }
   }
}

In the developers code, how can they pass in their logic when the button click of the control is successful?

protected override void CreateChildControls()
{
    var ctlMyControl = new MyControl();

    //ADD SuccessCode() TO ctlMyControl
    //SO IT IS TRIGGERED ON SUCCESS
    //MAYBE SOMETHING LIKE:
    //ctlMyControl.SuccessEvent = SuccessCode()??

    this.Control.Add(ctlMyControl);
}

protected void SuccessCode()
{
    //DO SOMETHING
}

How to I update MyControl to allow this?

  • 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-17T14:35:15+00:00Added an answer on May 17, 2026 at 2:35 pm

    You need to add an event to the control, like this:

    void btnSubmit_Click(object sender, EventArgs e) {
        //DO SOMETHING
        if (success) {
            OnSomethingCompleted();
        }
    }
    
    ///<summary>Occurs when the operation is successfully completed.</summary>
    public event EventHandler SomethingCompleted;
    ///<summary>Raises the SomethingCompleted event.</summary>
    internal protected virtual void OnSomethingCompleted() { OnSomethingCompleted(EventArgs.Empty); }
    ///<summary>Raises the SomethingCompleted event.</summary>
    ///<param name="e">An EventArgs object that provides the event data.</param>
    internal protected virtual void OnSomethingCompleted(EventArgs e) {
        if (SomethingCompleted != null)
            SomethingCompleted(this, e);
    }
    

    In the form, you can add a handler to the event, like this:

    myControl.SomethingCompleted += myControl_SomethingCompleted;
    
    void myControl_SomethingCompleted(object sender, EventArgs e) {
        //Do things
    }
    

    For more information, see the documentation.

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

Sidebar

Related Questions

There are other posts that say you can create a control in windows forms
I have created a custom control but I can't bind a property to the
For some reason our developers can only add projects that they've created to Team
Old Title: Prevent dynamically created control from retaining value Old Info: The reason I
I created a control with some items NSArray *items = [NSArray arrayWithObjects: @First, @Second,
I've created a control that extends the BoundField control to do some special processing
What gives? My previously created user control is visible, but the newly created one
I created a web control, and it needs some data from its parent page.
I created an ActiveX control ocx file using Visual Studio 2008. Then tried registering
I have created a TextBox control in DocumentViewer 's Toolbar for displaying the current

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.