views:

461

answers:

3

How do I setup a custom server control, so that it can be dragged into a design view in Visual Studio?

I have create a separate ASP.NET Server Control project and a custom MailLink control, basically by copying the code from this MSDN article: How to: Use Custom ASP.NET Server Controls in Visual Studio. The control works fine, if I manually register the library and insert the control in my web page with these two lines:

<%@ Register Namespace="Samples.AspNet" TagPrefix="Sample" %>
<Sample:MailLink runat="server" />

But how do I register / configure the control, so that it can be dragged into a design view i Visual Studio? If I drag my control from the solution explorer all I get is the path to the control. If add the dll from the server control project to my VS toolbox I get a clipboard FORMATETC error when I drag the control onto the design view.

+2  A: 

Here's a how to that I found more useful than the MSDN one.

http://www.osnews.com/story/6802/Visual_Studio_NET_Design_View_and_Custom_Web_Controls

Shaun Humphries
+1  A: 

This shows a step by step process of how to handle it http://www.newmobilecomputing.com/story/6802/Visual_Studio_NET_Design_View_and_Custom_Web_Controls/page4/

TStamper
+1  A: 

Just to make sure we're on the same page:

There are more than one type of control you can build in ASP.Net. Unfortunately, depending on what kind of control you build you can normally only get designer support for a control from Visual Studio at either the time when you are developing the control, or the time you are developing the page where the control will be used, but not both. Controls that are not supported will just show up as grey boxes.

IMO this was a major failure of Visual Studio/ASP.Net, but I digress. I have seen this limit overcome by using an ascx control with no code-behind.

Now that that's out of the way, let's move on.

It sounds like in this case you're working with a Server Control. You're in luck, because Server controls should get designer support from Visual Studio when you're building the page where the control is used. However, you need to make the control available to the project.

Server controls are normally compiled down to a dll assembly. You must include a reference for this file in your solution. At this point you should be able to right click in your toolbox and select Choose Items.... This will present you with a dialog box that will allow you to select your assembly. At this point your controls should show up in the toolbox.

Unfortunately, Visual Studio can at time be quirky about adding these controls. You may need to restart Visual Studio for them to be available. Note that I still use Visual Studio 2005, so hopefully things have improved in this respect for 2008.

Joel Coehoorn