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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:42:55+00:00 2026-05-13T06:42:55+00:00

Whilst writing a custom webpart for use in Sharepoint 2007 / WSS 3.0 I’ve

  • 0

Whilst writing a custom webpart for use in Sharepoint 2007 / WSS 3.0 I’ve come across a strange problem – when a button on my webpart is clicked, the event handlers are not firing.

Following the advise MSDN, Inside Sharepoint Services 3.0 and of course stackoverflow answers, I’ve overridden the CreateChildControls() method of System.Web.UI.WebControls.WebParts.WebPart.

The method looks like this:

protected override void CreateChildControls()
{

    // Get the ID from the master (pseudocode here to keep it short)
    if(ICrediteurIdProviderReference == null)
    {
        // We must have the detail-id or we can't load the form
        return;
    }

    // Call base
    base.CreateChildControls();

    // ** Creation of the rest of the form removed for clarity **

    // Create button
    Button saveButton = new Button();
    saveButton.ID = "SaveButton";
    saveButton.Text = "Save";
    // saveButton.CommandName = "Save";
    // saveButton.CommandArgument = "";

    // Register event handler
    saveButton.Click += new EventHandler(saveButton_Click);

    // Add button to page
    this.Controls.Add(saveButton);

}

For clarity I’ve removed the initiation of the rest of the form, as well as the creation of an HTML table within which the form is placed.

My event handler looks like this:

void saveButton_Click(object sender, EventArgs e)
{
    System.Diagnostics.Debug.WriteLine("saveButton_Click fired..");
}

Yup, that’s my default ‘simple debug’ event handler.

So far I’ve tried following these suggestions, but with no luck:

  • Setting CommandName and CommandArgument on the button (see commented out code)
  • Creating buttons in the OnInit() method instead of in CreateChildControls()

Starting to tear my hair out, but I assume it’s something really simple that I’ve missed. Any help would be greatly 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-05-13T06:42:55+00:00Added an answer on May 13, 2026 at 6:42 am

    Corrected thanks to comments 🙂

    It looks like CreateChildControls is called twice. The first time is before the binding of the provider values. The second time is after the binding.

    For the events to fire, the controls must be added the very first time CreateChildControls is called. The state must be loaded into the controls the second tiem CreateChildControls is called (i.e. once we have the record-id from the master via ICrediteurIdProviderReference).

    My new CreateClientControls() looks like this:

    protected override void CreateChildControls()
    {
    
        if (controlsLoaded == false)
        {
            LoadControls();
        }
    
        if (myProviderInterface != null)
        {
            LoadState(myProviderInterface.CrediteurId);
        }
    
    }
    

    controlsLoaded being a local boolean, which is set to true when LoadControls() has completed.

    Strange how writing your problem out properly then reading it back can actually help you solve it 🙂

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

Sidebar

Related Questions

Whilst starting to learn lisp, I've come across the term tail-recursive . What does
Whilst refactoring some code I came across some getter methods that returns a std::string.
Whilst trawling through some old code I came across something similar to the following:
This is the method I am attempting to use whilst trying to send a
Whilst analysing some legacy code with FXCop, it occurred to me is it really
Whilst refactoring some old code I realised that a particular header file was full
Whilst working on a recent project, I was visited by a customer QA representitive,
Whilst refactoring some legacy C++ code I found that I could potentially remove some
Whilst trying to get our app working in Firefox (I'm a big proponent of
Whilst investigating a memory leak I discovered that it was caused by calling NewRow()

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.