我正在调整一个Web应用程序,该应用程序具有WebSite和包含Web控件的类库。我的WebSite在设计时使用Project Reference引用程序集,Visual Studio会自动使用我的类库中的控件填充Toolbox。
问题是:当我将它们拖到ASPx设计器时,Visual Studio会自动创建一个TagPrefix,忽略我的类库的强键。这对我来说是一个问题,因为当我发布这个网站时,这个类库将是全局程序集缓存,如果TagPrefix没有正确引用它,将无法找到它。
在创建标记前缀时,有关如何强制visual studio考虑我的程序集强键的任何想法吗?
感谢。
答案 0 :(得分:0)
您是否已将TagPrefix attribute添加到课程库中?
来自MSDN
[assembly:TagPrefix("CustomControls", "custom")]
namespace CustomControls
{
// Simple custom control
public class MyCS_Control : Control
您还应该查看toolbox data attribute
namespace CustomControls
{
[ ToolboxData("<{0}:MyLabel Text='MyLabel' BorderColor='Yellow' BackColor='Magenta' BorderWidth = '10' runat='server'></{0}:MyLabel>") ]
public class MyLabel : Label
{
最后,在web.config中注册程序集
<system.web>
...
<pages>
...
<controls>
...
<add tagPrefix="yourPrefix"
namespace="MyAssembly.Some.Namespace"
assembly="MyAssembly" />
...
重建项目,然后将其中一个控件拖到页面上。