Joel's SharePoint Architecture Blog

SharePoint Server, SharePoint Online and Office 365 Training, Architecture, Administration and Development

  • Home
    • Sitemap
  • #SPThingADay
  • Articles
    • SharePoint Online
      • SharePoint Online – Drag and Drop and Large File Uploads
    • SharePoint 2016
    • SharePoint 2013
      • Content Database Changes to the AllUserData Table
    • SharePoint 2010
      • Administration
        • Disable CRL Checking
        • Excel 2010 & PowerPivot
        • Limits & Thresholds
        • PeoplePicker AD Errors
        • Recycle Bin Behaviour
        • Renaming a Server
        • Service Pack 1
        • Unattended Installs
        • Uninstall All SharePoint 2010 Solutions via PowerShell
        • User Alert Management
        • Virtualised SharePoint
        • Visio Stencils for Administrators
      • Development
        • Audience Membership Workflow Activity
        • Base Types, Lists & Content Types
        • BCS & Offline Sync
        • Debugger Skipping Lines
        • Development Laptop Spec
        • Enabling JavaScript IntelliSense
        • Event Receivers & Deployment Jobs
        • FavIcons & SPUrl
        • Google Maps Sandbox Web Part
        • Group By Content Type for List Views
        • Locale Stapler / Master or Default Locale
        • Removing Default Editor Parts
        • Sandbox Embedding Resources
        • Solution Sandbox Introduction
        • SPPersistedObject
        • Restoring Deleted SPSites in SP1
        • SPWebConfigModification 1
        • SPWebConfigModification 2
        • STSADM copyappbincontent vs. Install-SPApplicationContent
        • Workflows for Beginners
        • Workflow InitiationData Seralizer
    • SharePoint 2007
      • Alternate Access Mappings
      • Excel Services
      • Excel Services UDFs & Excel Client 2007
      • Experiences from the Field
      • InfoPath & Forms Server
      • Kerberos & SSRS
      • Records Management
      • Web Application Service
      • WSS vs MOSS
  • Training
    • SharePoint Admin Links
  • Downloads
    • Summary Slides for PowerPoint
    • CodePlex Projects
      • Audience Membership Workflow Activity
      • Google Maps Sandbox Web Part
      • Group By Content Type in List Views
      • Locale Stapler / Master or Default Locale
      • SharePoint Outlook Connector
  • Hire Me!
    • MCP Transcript
    • Résumé/CV

Do I Need To Invoke base.CreateChildControls in my WebParts?

January 28, 2013 by Joel Jeffery

This question was asked by one of my (most excellent) students this week:

In an ASP.NET Web Part for SharePoint, when I override CreateChildControls(), do I need to invoke the base?

You will see many examples on the Internet of code that does invoke the base, and many counter examples. Some of these contradictory examples are on the Microsoft MSDN site!

I decided to take ILSpy to the System.Web.dll assembly and find out once and for all.

First of all, System.Web.UI.WebControls.WebParts.WebPart does not override CreateChildControls() itself.

System.Web.UI.WebControls.WebParts

So, we must take a look at it’s ancestor: Part.

System.Web.UI.WebControls.WebParts.Part

Once again, there is no implementation for CreateChildControls() here, so we go further up the chain to System.Web.UI.WebControls.Panel:

System.Web.UI.WebControls.Panel

Still no definition of CreateChildControls(). Further up, we get System.Web.UI.WebControls.WebControl.

System.Web.UI.WebControls.WebControl

But it is not until we get to System.Web.UI.Control that we have an implementation:

System.Web.UI.Control

Hang on a moment! That’s empty!

// System.Web.UI.Control
/// <summary>Called by the ASP.NET page framework to 
/// notify server controls that use composition-based 
/// implementation to create any child controls they contain
/// in preparation for posting back or rendering.</summary>
protected internal virtual void CreateChildControls()
{
}

So, the simple answer appears to be:

No, you don’t need to invoke base.ControlChildControls() in an ASP.NET WebPart”

Share this:

  • Share
  • Twitter
  • Facebook
  • LinkedIn
  • Reddit
  • Print
  • Email

Filed Under: SharePoint 2010 Tagged With: ASP.NET, Development, SharePoint 2010, SharePoint Development

Joel is a full-stack cloud architect who codes. He is a Microsoft Certified SharePoint 2016, SharePoint Online and Azure specialist and Microsoft Certified Trainer.
He has over 17 years' experience with SharePoint and the Microsoft .NET Framework.
He's also Director at Microsoft Gold Partner JFDI Consulting Ltd. Read More…

#SPThingADay

Load More…

Recent Posts

  • SharePoint Thing a Day – 073 – SharePoint Information Architecture. Content Type Hub Gotchas
  • SharePoint Thing a Day – 072 – SharePoint Information Architecture. The Content Type Hub
  • SharePoint Thing a Day – 071 – SharePoint Information Architecture. Content Type Management Options.
  • SharePoint Thing a Day – 070 – SharePoint Search. Result Types and Display Templates.
  • SharePoint Thing a Day – 069 – SharePoint Search. Crawl Rules vs Crawler Impact Rules.
Joel's Acclaim Profile
Joel's Microsoft Profile

Tags

Administration Architecture Certification Cloud Development Information Architecture intranets MCP Microsoft Microsoft Architecture Microsoft Azure migration Mobile Development MOSS MOSS 2007 office365 Office 365 Office 365 PowerShell SaaS SharePoint SharePoint 2010 SharePoint 2010 Training SharePoint 2013 SharePoint Administration SharePoint Administrator SharePoint Architecture SharePoint Designer 2010 SharePoint Developer SharePoint Development sharepointonline SharePoint Online SharePoint Search SharePoint Training SharePoint Videos Silverlight SOA Solution Sandbox SPThingADay TechEd 2007 Training Videos Visual Studio 2010 Windows Phone 7 WSS
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright © 2019 Joel Jeffery, SharePoint Architect

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.