1

Since ASP.NET 2.0 I usually register reusable user controls in web.config, rather then register it in every page with <%@ Register %> directives.

UPDATED See ScottGu's blog for what I mean.

Is there any "Sharepoint way" to do it for Sharepoint (2010/2013) development?

  • Can you use web parts? – Nico Mar 20 '14 at 12:15
  • User control is shared between _layouts and rendering control – dbardakov Mar 20 '14 at 12:16
2

While developing for SharePoint 2010/2013 using Visual Studio 2010/2012/2013, Microsoft provides an excellent integration to package third-party assemblies and safe control entries via package designer.

Package designer not only helps you with packaging you SharePoint solutions but also allows you to add the assembly references, SafeControl entries and user controls.

Think twice before fiddling and manipulating web.config via SPWebConfigModification

Good luck!

| improve this answer | |
1

create your user control

then add to masterpage:

<%@ Register TagPrefix=”myUserControl” TagName=”myUserControlPage” Src=”~/_controltemplates/myUserControlFolder/myUserControlPage.ascx” %>

now all you need todo is add the control to where ever you want using this:

<myUserControl:myUserControlPage ID=”myUserControl” runat=”server” />

very simple solution! just like how layouts and masterpage works!

| improve this answer | |
  • Interesting, what's the overhead? – dbardakov Apr 3 '15 at 14:00
0

This is the best way to do it.

You can programmatically modify the web config on feature activated/deactivated to maintain and update whatever web config is being used when you activate your feature. Keep in mind the scope of your feature however.

A few more options but I don't suggest manual updating.

| improve this answer | |
0

I already created different custom user control that I use in different web part or application page.

  1. Open Visual Studio and create an Empty SharePoint Project
  2. Right click on the project item and add a user control, visual studio creates different folder and files
  3. Write your code
  4. Publish (create a wsp file)
  5. Deploy it on your farm.

The control is stored under the following folder C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\CONTROLTEMPLATES\Your_Project_Name\User_Control_Name.ascx

And then you can use it on your web page using

<%@ Register TagPrefix="yourprefix" Src="/_controltemplates/15/Your_Project_Name/User_Control_Name.ascx" TagName="yourtagname" %>
| improve this answer | |
  • It's not about creating custom user control, it's about reusing existing one without the need to register it in every page/control. – dbardakov Oct 9 '15 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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