How can I add a custom user control to a page layout?
I have some custom user control developed. I want to place it in a custom page layout. So it will be in every page instance of that layout.
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityFirst create your User Control and publish is to SharePoint.
Then you register a tag for your control
<%@ Register Tagprefix="MyControls"
Namespace="KM.MyControls.MyControl"
Assembly="KM.MyControls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=<Your token>" %>
Then you can reference your User Control
<MyControls:MyUserControl runat="server"/>
Make sure you put the user control into a subdirectory of {SharePointRoot}/Templates/ControlTemplates
Put a Register
element at the top of you page-layout
<%@ Register TagPrefix="MyOwnPrefix" TagName="MyUserControl" Src="~/_controltemplates/MyProjectName/UserControl.ascx" %>
and the refer to it where you need it like:
<MyOwnPrefix:MyUserControl runat="server" id="userControl" />
{SharePointRoot}/Templates/ControlTemplates
create a subdirectory and put the UserControl there
Sep 28, 2012 at 6:57