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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:10:49+00:00 2026-05-14T07:10:49+00:00

I have a control that handles commenting. In this control, I have set a

  • 0

I have a control that handles commenting. In this control, I have set a delegate event handler for sending an email.

I then have various types of controls, e.g. blog, articles etc, each of which may or may not have the commenting control added (which is done dynamically with me not knowing the id’s), i.e. the commenting control is added outside this control. Each of these controls handles it’s emailing differently(hence the event).

What I’m trying to determine, is how to assign the event in the parent control. At the moment, I’m having to recursively search through all the controls on the page until I find the comment control, and set it that way. Example below explains:

COMMENTING CONTROL

public delegate void Commenting_OnSendEmail();

public partial class Commenting : UserControl
{
   public Commenting_OnSendEmail OnComment_SendEmail();

   private void Page_Load(object sender, EventArgs e)
   {
      if(OnComment_SendEmail != null)
      {
          OnComment_SendEmail();
      }
   }
}

PARENT CONTROL

public partial class Blog : UserControl
{
   private void Page_Load(object sender, EventArgs e)
   {
      Commenting comControl = (Commenting)this.FindControl<Commenting>(this);
      if(comControl != null)
      {
         comCtrol.OnComment_SendEmail += new Commenting_OnSendMail(Blog_Comment_OnSendEmail);
      }
   }
}

Is there an easier way?

EDIT:

The reason I ask is that if I search from this.Page as the initial control, I am worried about time taken to search down the control tree to find it. Each different type of page would be different in how many control it would have. On some testing, it returns back quite quickly the result.

  • 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-14T07:10:49+00:00Added an answer on May 14, 2026 at 7:10 am

    You could override the AddedControl event of your Blog class and check if the added control is instance of type Commenting. Something like:

    public partial class Blog : UserControl { 
    
        protected override void AddedControl(Control control, int index) {
          base.AddedControl(control, index);
    
          Commenting commentingControl = control as Commenting;
          if (commentingControl == null) return;
    
          commentingControl.OnComment_SendEmail += new Commenting_OnSendMail(Blog_Comment_OnSendEmail);
        }
    }
    

    Of course, you can put this code on a base class of all your “commentable” user controls and have an abstract method to actually handle the event.

    Just one thing: the AddControl event happens AFTER the Page_Load, so be careful.

    Cheers,

    André

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

Sidebar

Related Questions

I have a class that handles events from a WinForms control. Based on what
I have an ASPX page and on this page I have a control that
I have an extender control that raises a textbox's OnTextChanged event 500ms after the
I have a control that, upon postback, saves form results back to the database.
I have a control that is created like so: public partial class MYControl :
I have a control that is basically functioning as a client-side timer countdown control.
I have a control that I'm writing where I want to turn off .NET's
I have a custom control that implements IPostBackEventHandler. Some client-side events invoke __doPostBack(controlID, eventArgs).
We have created a control that needs to persist data via the ViewState property
I have an Panel control that I need to maintain position across postbacks. I

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.