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>
link|improve this question

78% accept rate
feedback

2 Answers

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 !

link|improve this answer
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 Nov 3 '10 at 15:35
Absolutely right. Glad you found your precise solution :) – Sébastien Levert Nov 3 '10 at 15:39
feedback
up vote 0 down vote accepted

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

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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