I have a custom user control.I want to add the following code at the time of activating feature in page layout.

<%@ Register Tagprefix="MyControls" Namespace="MyControl" 
  Assembly="MyControls, Version=, Culture=neutral, PublicKeyToken=XXX" %>

<MyControls:MyUserControl runat="server"/>
  • 1
    which following code? Sep 1, 2014 at 7:08
  • @VarunVerma corrected the code formatting, now you can the code
    – SPArcheon
    Sep 1, 2014 at 7:29
  • Shubhashis, the control needs to be placed in a specific position on the page?
    – SPArcheon
    Sep 1, 2014 at 7:30
  • Thanks for reply.. I want to add one custom user control in the page layout programtically. I think to get that user control I have to add that register element in page layout.Hence I have to add that register element programtically. Sep 1, 2014 at 8:09

1 Answer 1


What you're describing is a modification of ASP.NET markup (not code), which I think is not the best way to handle this issue programmatically.

Better add or reuse a content placeholder and make this a delegate control if possible. You can find a how-to on MSDN: How to: Customize a Delegate Control‎.

You can read more on the architecture of SharePoint pages on MSDN: Overview of the SharePoint 2013 page model.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.