I think a webpart will work either way, because a webpart is just a more advanced webcontrol. I would do it one of two ways:
- Add it to the master page or page layout using SP Designer.
- Add it to every page programmically using a feature
1 is if you need the webpart to exist where there isn't a webpart zone. You'll need to make the change to every different instance of the master page or page layout that you will want to have the control on. Most people just have one master page so this could be an easy win.
2 limits you to just pages that have web part zones. Remember adding a webpart programmically requires it be added to a zone.
The code to add a webpart looks like this:
ContentEditorWebPart webpart = new ContentEditorWebPart();
webpart.ChromeType = PartChromeType.TitleOnly;
webpart.Title = "Content Editor";
XmlDocument xmlDoc = new XmlDocument();
XmlElement xmlElement = xmlDoc.CreateElement("MyElement");
xmlElement.InnerText = "My Text";
webpart.Content = xmlElement;
using (SPLimitedWebPartManager mgr = web.GetLimitedWebPartManager(pageUrl, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))
{
try
{
mgr.AddWebPart(webPart, "MiddleLeftZone", 0);
}
finally
{
if (mgr != null &&
mgr.Web != null)
{
mgr.Web.Dispose();
}
}
}