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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:24:50+00:00 2026-06-17T17:24:50+00:00

I have a problem in a complex bit of code. It appears that a

  • 0

I have a problem in a complex bit of code. It appears that a delegate method call is interrupting the click event of a dynamically added button. I haven’t coded up a basic example to be 100% sure but it looks like that’s what’s happening.

We have a .aspx page which contains a user control

<wachter:ViewEditTemplateControl ID="veSiteInfo" runat="server" Mode="View" EnableAjax="false" CanEditPermission="SiteInfoCanEdit">
                                <ViewButtonsTemplate>
                                 <asp:ImageButton ID="ibMap" CommandName="Map" ImageUrl="../Images/NavIcons/map.png" Visible="true" ToolTip="Site Map" runat="server" />
                                 <asp:ImageButton ID="ibtnSiteNotes" CommandName="SiteNotes"  ImageUrl="/Images/iconInfo.png" visible="false" ToolTip="Site Notes" runat="server"  />
                                 <asp:ImageButton ID="imgEdit" CommandName="Edit" ToolTip="Edit" runat="server" ImageUrl="/Images/iconEdit.png" />
                                </ViewButtonsTemplate>
                                <ViewTemplate>
                                    <uc1:SiteInformationView ID="SiteInformationView1" runat="server" />
                                </ViewTemplate>
                                <EditTemplate>
                                    <uc1:SiteInformationEdit ID="SiteInformationEdit1" runat="server" />
                                </EditTemplate>
                            </wachter:ViewEditTemplateControl>

In the .aspx’s codebehind we set a delegate to the ViewTemplate’s usercontrol

protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        (veSiteInfo.FindControl("SiteInformationView1") as JobSiteViewControl).SiteChanged += SiteChanged;
    }

This delegate is used to set the visibility of our edit button imgEdit.

The ViewEditTemplateControl contains a bit of code in the codebehind which dymaically adds save/edit buttons

Button btnSave = new Button();
            btnSave.ID = "btnSave";
            btnSave.Text = "Save";
            btnSave.CommandName = "Save";

            root.Controls.Add(btnSave);

            Button btnCancel = new Button();
            btnCancel.ID = "btnCancel";
            btnCancel.Text = "Cancel";
            btnCancel.CommandName = "Cancel";
            btnCancel.CausesValidation = false;

            root.Controls.Add(btnCancel);

In the ViewTemplate’s codebehind we call this delegate on page init.

public Action<JobSiteEntity> SiteChanged;

public override void InitControl() 
{

    if (SiteChanged != null)
            SiteChanged(DataItemTyped); 
}

The problem is that clicking the dynamically added btnCancel triggers the delegate but doesn’t fire the event handler for it.

If I comment out setting the delegate, the button’s event handler gets hit.

I know my code snippets aren’t the best but any ideas would be appreciated.

  • 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-17T17:24:51+00:00Added an answer on June 17, 2026 at 5:24 pm

    Not the best solution, but I’ve ended up removing the delegate call and directly accessing a method on the base page.

    if (Page is IJobEntityPage)
            {
                ((IJobEntityPage)Page).SetEditVisibility(DataItemTyped);
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My problem is a little bit complex. I have the following code: $(document).ready(function() {
A bit of a complex problem to describe here: I would like to have
I have a very simple bit of code that won't work, and have no
I have a slightly complex problem here. I need to show to the client
I have a complex MySQL problem. SELECT * FROM banners, content_id_country, languages WHERE content_id_country.content_id
I have a complex sorting problem with my SQL statement. I have a table
I have a complex SQL problem in MS SQL Server, and in drawing on
I have a reasonably complex layout problem: I would like to have a main
I have a complex JPA/Hibernate problem. I have two entities A and B. A
I have a User table that has a BIT NULL column called NxEnabled ,

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.