我有以下控件:
public partial class Controls_ProductPanel : System.Web.UI.UserControl
{
private int _ProductID;
public int ProductID
{
get
{
return _ProductID;
}
set
{
_ProductID = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
我希望能够将其添加到这样的页面中:
Controls_ProductPanel panel = new Controls_ProductPanel();
panel.ProductID = 2;
Page.Controls.Add(panel);
但Visual Studio似乎没有重新审核Controls_ProductPanel
我明白了:
The type or namespace name 'Controls_ProductPanel' could not be found. (Are you missing a using directive or an assembly reference?)
答案 0 :(得分:1)
为了解决这个问题,我必须将注册标记放在.aspx页面上。这允许我访问它的类型。
<%@ Register TagName="ProductPanel" TagPrefix="uc" Src="~/Controls/ProductPanel.ascx" %>
答案 1 :(得分:-1)