0

I have a number of custom web parts which have similar functions and properties shared through each of them. Each have a subset of a larger set of functions, rather than redevelop the same controls over and over, is there a way I can build the user controls and then just drag and drop it on to my Visual Web Part as I would any other web project?

What I have is structured as follows:

  1. A number of web parts
  2. A Mapped folder for ControlTemplates with a sub folder for MyCustomControls
  3. User controls in the MyCustomControls folder.

When I drag and drop the user control into my Visual Web Part User control, all it does is add the path to the web part user control as a string. i.e. D:\Source\MyProject\ControlTemplates\MyCustomControls\CustomControl.ascx

There is nothing difficult in the web part yet, its purely HTML markup (at the moment):

<a href="#" id="dialog_link" class="floatright">
Content Title
</a>
<!-- ui-dialog -->
<div id="dialog" title="Content Title">
    <p>Brief content</p>
    <a href="#">Read More</a>
</div>

2 Answers 2

1

You need to make a reference to it in your container webpart. Like this :

<%@ Register Tagprefix="MyTagPrefix" Namespace="My.WebControls.Namespace" Assembly="My.Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=MYPUBLICKEYTOKEN" %> 

Then, you can use this new refered namespace this way in your container webpart :

<MyTagPrefix:MyControl id="Control1" runat="server"/>

Good luck !

2
  • 1
    I found the issue, the user control was referenced as you said but was placed in the mapped folder ControlTemplates, however ControlTemplates is actually referred to as _ControlTemplates when running SP2010, the solution was to change the mapped folder in VS to _ControlTemplates mimicking the safe entry in the web.config
    – Mauro
    Commented Nov 3, 2010 at 15:35
  • Absolutely right. Glad you found your precise solution :) Commented Nov 3, 2010 at 15:39
0

I found the issue, the user control was referenced as @Sébastien Levert said but was placed in the mapped folder ControlTemplates, however ControlTemplates is actually referred to as _ControlTemplates in the web.config when running SP2010, the solution was to change the mapped folder in VS to _ControlTemplates mimicking the safe entry in the web.config

Your Answer

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

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