大网数据广告活动
Web服务器与PHP

Register assembly to use custom control

· 52CE 我爱测

This article explains how to register an assembly in a WebForm to use a custom control.

This article provides information to make and register an assembly available in a WebForm to use with ASP.NET custom server controls.

Original product version:   ASP.NET
Original KB number:   321749

Sample assembly properties

To be represented as a Custom Server Control, the assembly must have a class that directly or indirectly derives from System.Web.UI.Control and you must enclose the class in a namespace. Samples in this article assume that the class is enclosed in the CustomControlNamespace namespace, and that the assembly was successfully compiled in a file named CustomControl.dll.

Make an assembly available to ASP.NET application

To make an assembly available for an ASP.NET application, you must place the assembly's .dll into the /bin folder of the application.

  1. Navigate to the root directory of the application in Windows Explorer.

    To find out what the application project folder is:

    1. In the .NET environment, under the View menu, select Solution Explorer.
    2. Right-click a project main item in Solution Explorer and select Properties.
    3. In the Project Properties dialog box, select Common Properties and select General.

    In the tree pane, you see the list with the Project Folder property. This is typically the root directory of the application.

  2. In a Web Application project folder, create a folder named bin if it doesn't exist.

  3. Copy or move the assembly's .dll in this folder. You can now use the control from any ASP.NET page in your application's root directory (or any of its subfolders).

Register the assembly in an ASP.NET application web form

In a .NET programming environment, open the Form.aspx source window and add the following tag at top of the code:

<%@ Register TagPrefix="Custom" Namespace="CustomControlNamespace" Assembly= "CustomControl" %>

In the code above:

  • Custom is an alias that you associate with a namespace.
  • CustomControlNamespace is a namespace in which classes of an assembly are enclosed.
  • CustomControl is the name of the assembly file without an extension (.dll).

In your code, change these parameters to the appropriate names for your assembly.

Now the assembly is registered in a Web Form. You can use this registered assembly in your ASP.NET code with the chosen names. For example, the tag could be:

<Custom:CustomControl id="CustomControl1" parameter1="value1" parameter2="value2" runat="server"/>

In the tag above, Custom is the chosen name for the assembly's namespace, CustomControl is the custom server control name, and parameter 1 and parameter2 are optional control properties that vary based on your actual code.

Source: Microsoft Learn / IT Pro troubleshooting by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / IT Pro troubleshooting
适用范围
See source applicability · Source date 03/25/2020
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。