我想在我的网站上做一个自定义控件(注意:不是 web 应用程序)
代码如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AnkitControls
{
/// <summary>
/// Summary description for CustomTreeView
/// </summary>
public class CustomTreeViewControl : WebControl
{
}
}
默认.aspx:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AnkitControls" Namespace="AnkitControls" TagPrefix="CustomCtrl" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Welcome to ASP.NET!
</h2>
<p>
To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>.
</p>
<p>
You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&clcid=0x409"
title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
</p>
</asp:Content>
当我编译网站时,它给我错误提示。
错误 = “命名空间‘AnkitControls’中不存在类型或命名空间名称‘AnkitControls’(您是否缺少程序集引用?)”
最佳答案
正确使用Register
标签:
<%@ Register TagPrefix="my" TagName="control" Src="~/Path/To/Your.ascx" %>
您指定的语法适用于您的控件位于另一个程序集中的情况。
关于c# - asp.net在网站中添加自定义控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6903754/