Let’s say you have created a custom control and added it to the toolbox and ready to use it on a page (Or, let’s say, you created a custom control and a page developer has added it to the toolbox and is getting ready to use it on a page).
Default behavior
If the page developer drags the custom control and drops it on a page, it would add two lines like the following:
At the top of the page, the custom control will be registered with the @Register directive. In the @Register directive, you will see the TagPrefix set to cc1. This is the default value that stands for custom control 1.
<%@ Register Assembly="AJAXWrite" Namespace="AJAXWrite" TagPrefix="cc1" %>
In the body of the page, you will see the actual declarative placement of the AJAXWrite custom control. Here you will see the prefix cc1 again.
<cc1:AJAXWrite ID="AJAXWrite1" runat="server" />
The above declaration comes from the class level attribute you set on the custom control class.
[ToolboxData("<{0}:AJAXWrite runat=server></{0}:AJAXWrite>")]
public class AJAXWrite : WebControl, IPostBackDataHandler
The attribute ToolboxData is the template for the declaration you see in the source window of the page. In this case, the name of the custom control is AJAXWrite and the attribute ToolboxData is right above it.
Now, you want to change cc1 to something more meaningful. Since this control is called AJAXWrite, the prefix could be something like ajw. There are two ways of changing this:
- Change the prefix manually on the page
- Change it with an assembly level attribute
Figure 1. Tag prefixes inside the page and the custom control

Changing Prefix Manually
Go into the source window of the page (e.g. default.aspx) and manually change the TagPrefix from cc1 to ajw.
<%@ Register Assembly="AJAXWrite" Namespace="AJAXWrite" TagPrefix="ajw" %>
<ajw:AJAXWrite ID="AJAXWrite1" runat="server" />
Don’t forget to change prefix at both the places: in the @Register directive and in the actual declaration. Otherwise, you will get the following error: Unknown server tag.
The advantage of this approach is that the page developers can change this prefix to whatever the string that makes sense to them.
Set a meaningful prefix with the help of assembly level attribute
Another approach is to have meaningful TagPrefix set in the custom control code by the control developer. This prefix can still be changed by the page developer, but it would at least be a bit more meaningful (it won’t be cc1).
This can be achieved by using an assembly-level attribute: TagPrefix.
[assembly: TagPrefix("AJAXWrite", "ajw")]
namespace AJAXWrite
{
In the above example, the AJAXWrite namespace contains the custom control AJAXWrite. So, the TagPrefix attribute added above that takes the namespace and tag prefix as the parameters.
With the above attribute in the custom control, if you drag-drop the AJAXWrite custom control from the toolbox, the default tag prefix used on the page will be ajw, as shown below:
<%@ Register Assembly="AJAXWrite" Namespace="AJAXWrite" TagPrefix="ajw" %>
<ajw:AJAXWrite ID="AJAXWrite1" runat="server" />