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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:26:18+00:00 2026-05-13T09:26:18+00:00

I have a simple user control that contains some buttons that fire events which

  • 0

I have a simple user control that contains some buttons that fire events which I want to be handled by the page using the control. I have my code setup as such:

public event EventHandler Cancel;
public event EventHandler Confirm;
public void Confirm_Click(object sender, EventArgs e)
{
    if (Confirm != null)
        Confirm(this, e);
}
public void Cancel_Click(object sender, EventArgs e)
{
    if (Cancel != null) 
        Cancel(this, e);
}

but when I try to call these from the page that is using the control’s page load event I don’t get any of the custom events

ASPX Code

<%@ Register TagPrefix="btg" TagName="CustomControl" Src="~/Search/CustomControl.ascx" %>
<btg:CustomControl ID="btgControl" runat="server" ></btg:CustomControl>

could this be because my buttons in the user control are within an update panel?

  • 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-13T09:26:19+00:00Added an answer on May 13, 2026 at 9:26 am

    You shouldn’t be seeing methods. You should be seeing events.

    In your parent page’s load, you need to do this:

    myUserControl.Cancel += new EventHandler(myUserControl_Cancel);
    

    You can hit tab,tab to auto-generate the method stub. That will look like:

    void myUserControl_Cancel(object sender, EventArgs e) {}
    

    Then, this code will fire after it is called in the method of your user control. In order for that code to fire, you’ll have to assign the events to button events on your user control.

    edit: myUserControl is the id of your user control. Also, some would argue that event handlers should be in your page’s init method.

    edit:

    Is your user control properly referenced in the page? i.e. Are you registering the user control in web.config or using the reference directive in the page?

    Also, did you try cleaning the solution and rebuilding? If your user control is dynamically created/loaded, you’ll have to wire up the events in the same scope as the instantiated control. In order to dynamically load the user control, you’ll have to have a placeholder in your page and do the following:

    UserControl control = Page.LoadControl("~/ControlPath/ControlName.ascx");
    ((MyUserControlClass)control).Cancel += += new EventHandler(myUserControl_Cancel); // etc...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.