SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

(x-post from

I have a Custom SharePoint 2010 Visual Web Part which I've realized is calling the CreateChildControls() method twice. I've tried setting the ChildControlsCreated property (it does not stay set and resets to false), checking for !Page.IsPostBack and calling Controls.Clear(), all to no avail.

Here's the code for the web part:

//using statements redacted.

namespace MyNamespace.MyWebPart
    public class MyWebPart : WebPart
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/MyNamespace/MyWebPart/MyWebPartUserControl.ascx";

        protected override void CreateChildControls()
            Controls.Clear(); //removing this line makes no difference
            Control control = Page.LoadControl(_ascxPath);
            this.ChildControlsCreated = true; //this line also makes no difference

This Web Part is on the NewForm.aspx, EditForm.aspx and DispForm.aspx pages and I've discovered that left-clicking on a list item (that will bring up EditForm.aspx with my web part in a modal window) causes the double-call, but opening the list item in a new tab will not have the issue.

Any ideas?

share|improve this question
I think is a debug issue... I'm not pretty sure 100% – Salvatore Di Fazio Jun 13 '13 at 13:06
I've tried Debug and Release, with Debugger attached and detached - no difference. – Ryan Shripat Jun 13 '13 at 17:24
What about the other methods like OnLoad and OnInit? Are these methods also called twice? – banana Jun 19 '13 at 14:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.