I wrote a custom control inherited from WebControl. (Note: not a user control).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
namespace Taopi.WebComponents
{
public class RatingLabel : WebControl
{
public RatingLabel()
: base("span")
{ }
//...
I placed it in /App_Code, and on a web page it is registered and used as following:
<%@ Register TagPrefix="uc" Namespace="Taopi.WebComponents" %>
...
<uc:RatingLabel Rating='<%# Eval("rating") %>' runat="server" />
They run well until I move RatingLabel to /Components, which is folder cerated by me. I got an error saying “Unknown server tag uc: RatingLabel” when I try to run the website.
I believe the registration is wrong, so what modification is needed? Must custom controls be placed in the App_Code?
I have another question that where do you usually place your custom controls (except for refering a external DLL)? Are there any “suggested” locations?
I’ve run into this before. The only way I’ve found you can store code outside of the AppCode folder is to add a “Class Library” project or external DLL as you suggested (which is my preferred approach anyhow as it offers use across multiple projects).
Alternatively, if you use a “Web Application” project type instead of a “Web site” project, you can store code anywhere.