Reference a custom ASP.NET control
To work with a custom ASP.NET control in an ASP.NET page, you must reference the custom control in either the page, the master page assigned to the page, or a web.config file. Referencing the custom control in a web.config file is useful if you want to use the custom control in multiple pages of your site.
Note
To work with custom ASP.NET controls in Microsoft Expression Web, you also need to make the custom control available to Expression Web and add the custom control to the Code view of your page. See Add a custom ASP.NET control to a website and Add a custom ASP.NET control to a page.
To reference a custom ASP.NET control in an ASP.NET page
Display your page in Code or Split view.
In the code pane, add the following line of code at the beginning of the page:
<%@ Register assembly="ASSEMBLY_NAME" namespace="ASSEMBLY_NAMESPACE" tagprefix="TAG_PREFIX" %>
In the line of code you added in the previous step, replace
ASSEMBLY_NAME
with the name of the custom control assembly file, excluding the file extension; replaceASSEMBLY_NAMESPACE
with the value specified in the documentation for your custom control; and replaceTAG_PREFIX
with any name without spaces.Note
If the custom control is installed in the Global Assembly Cache (GAC) on your computer instead of placed in the bin folder of your site, replace ASSEMBLY_NAMESPACE with the fully qualified type name, version, public key token, and culture for your control. For more information, see @Register in the MSDN library.
To reference a custom ASP.NET control in a web.config file
Open your site's web.config file.
If your site doesn't have a web.config file, create one and save it in the root folder of your site. For information, see Create a web configuration file.
If the web.config file doesn't already contain
<pages> <controls> </pages></controls>
tags, add them after the<system.web>
tag and before the</system.web>
tag.Add the following code anywhere after the
<system.web><pages><controls>
tags and before the</system.web></pages></controls>
tags:<add tagprefix="TAG_PREFIX" assembly="ASSEMBLY_NAME" namespace="ASSEMBLY_NAMESPACE" />
Replace
ASSEMBLY_NAME
with the name of the custom control assembly file, excluding the file extension; replaceTAG_PREFIX
with any name without spaces; and replaceASSEMBLY_NAMESPACE
with the value specified in the documentation for your custom control.Note
If the custom control is installed in the Global Assembly Cache (GAC) on your computer instead of placed in the bin folder of your site, replace ASSEMBLY_NAMESPACE with the fully qualified type name, version, public key token, and culture for your control. For more information, see @Register in the MSDN library.
See also
Tasks
Add a custom ASP.NET control to a website
Add a custom ASP.NET control to a page
Concepts
Send feedback about this topic to Microsoft. © 2011 Microsoft Corporation. All rights reserved.