CHunky Universe of Vigourous Astonishing SHarepoint :)

Tag Archives: webparts

Webpart in a reusable user control

In my previous post I wrote about using IgnoreIfAlreadyExists=”True” for preventing of adding webparts multiple times. It works fine until you redeploy your project. Another approach is to use a user control with you webpart. Add mapped folder CONTROLTEMPLATES.

Create a new user control, add you assembly and your webpart. Then you can add this user control wherever you need it.

<%@ Register 
    Assembly="Microsoft.SharePoint.Portal, Version=, 
    Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<SPSWC:SocialCommentWebPart runat="server" 
Title="Note Board" 
 MissingAssembly="Cannot import this Web Part." 
 Description="Enable users to leave short, publicly-viewable notes about this page." 

Then add your user control into page layout like this:

<%@ Register 
    Src="~/_CONTROLTEMPLATES/CONTOSO/SocialCommentUserControl.ascx" %>
<CONTOSO:SocialComment id="SocialComment" runat="server" />

Webparts on a layoutpage which is provisioned several times

It is pretty easy to add webparts to a layout page. Just define the webparts in the corresponding Elements.xml file. Like you do in onet.xml. It works fine if you provision just a single page with this layout on a web. If you have multiple pages that use the same page layout (e.g. in WCM). The trick is to use the attribute IgnoreIfAlreadyExists in the File tag:


Custom Title on built-in webpart

What to do if you want to change the title in the built-in webpart like Tasks or so. Your own title or just to avoid tasks (1) and tasks (2) if you add two views of them to a page. In onet.xml you add them as view:

  BaseViewID="7" WebPartZoneID="Middle" 

The solution is to add cdata element and webpart tag within it. So now replace this with:

  BaseViewID="7" WebPartZoneID="Middle"
    <WebPart xmlns="">
      Microsoft.SharePoint, Version=, Culture=neutral,
    <Title>Task Title as I want it</Title>

Now you can change the title, and all other properties (chrometype, helpurl and more) as you want. One thing is to mention. If you just copy the onet.xml to the Sharepoint Root (as you can do with CKSDev), you must restart IIS:

iisreset /noforce

Webpart Livscykel

OnInit – Configuration values set using WebBrowsable properties and those in web part task pane are loaded into the web part.

LoadViewState – The view state of the web part is populated over here.

CreateChildControls – All the controls specified are created and added to controls collection. When the page is being rendered for the first time the method generally occurs after the OnLoad() event. In case of postback, it is called before the OnLoad() event. We can make use of EnsureChildControls() – It checks to see if the CreateChildControls method has yet been called, and if it has not, calls it.
User Generated Event – for e.g. button click on the web part.
OnPreRender – Here we can change any of the web part properties before the control output is
RenderContents – Html Output is generated.
SaveViewState – View state of the web part is serialized and saved.

Ändra content i ContentEditorWebPart

Det finns ett exempel här.

//defaultAspx är sidan (SPListItem i Sidor)
//måste checkas ut först
//mgr är WebPartManager
//wp är contentEditorWebPart
web.AllowUnsafeUpdates = true;
XmlDocument xmlDoc = new XmlDocument();
XmlElement xmlElement = xmlDoc.CreateElement("Content");
xmlElement.InnerText = ((Microsoft.SharePoint.WebPartPages.ContentEditorWebPart)wp).Content.InnerText.ToString();
xmlElement.InnerText = xmlElement.InnerText.ToString().Replace("#HEADING#", "Welcome for welcome");
wp.Content = xmlElement;
web.AllowUnsafeUpdates = false;

Man måste skapa nytt XmlDocument och XmlElement, om man försöker skriva direkt till wp.Content.InnerText kommer det inte uppdateras. I det här fallet, byter vi ut #HEADING# mot något mer passande.


Lägg till en kommentarruta i din sida. Gör det lite till webb2.0. Här finns lite info. På denna sida står det hur man kan lägga till webparten mha xml.

You can even provision a social comment webpart like it is done in my site:

<File Url="person.aspx" Type="Ghostable">
    <AllUsersWebPart WebPartZoneID="MiddleLeftZone" WebPartOrder="3">
        <WebPart xmlns="">
            <Assembly>Microsoft.SharePoint.Portal, Version=, 
                    Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>

Gratis webparts från Amrein

Finns gratis webparts från Amrein Engineering. Fått tips från Testat AELightBox. Men det är rätt så krångligt med inställningar. Den kräver att man skriver in vilken vy och så vidare. Vyn ska ha “title” och den kräver även kolumner så som ImageWidth och ImageHeight. Detta känns lite mindre användbart eftersom de här värdena kunde man hämta från bilden själv och anpassa till skärmens upplösning.

Amrein Lightbox

Вула Чăвашла

VulaCV - Чăвашла вулаттаракан сайт

Discovering SharePoint

And going crazy doing it

Bram de Jager - Coder, Speaker, Author

Office 365, SharePoint and Azure

SharePoint Dragons

Nikander & Margriet on SharePoint

Cameron Dwyer

Office 365, SharePoint, Azure, OnePlace Solutions & Life's Other Little Wonders


Me and My doings!

Share SharePoint Points !

By Mohit Vashishtha

Jimmy Janlén "Den Scrummande Konsulten"

Erfarenheter, synpunkter och raljerande om Scrum från Jimmy Janlén

Aryan Nava

DevOps, Cloud and Blockchain Consultant


SharePoint for everyone


Ryan Dennis is a SharePoint Solution Architect with a passion for SharePoint and PowerShell

SharePoint 2020

The Vision for a Future of Clarity

Aharoni in Unicode

Treacle tarts for great justice

... And All That JS

JavaScript, Web Apps and SharePoint


Mostly what I know about SharePoint - CommunicoCuspis


SharePoint på ren svenska