我在学习自定义控件,我写了一个mycontrol.cls文件用来输出hello world字样,文件如下:
Imports System
Imports System.Web
Imports System.Web.UI
Namespace mycontrols
public Class mycontrol:Inherits Control
protected overrides Sub Render(output as HtmlTextWriter)
output.Write("hello worldW! davie")
End Sub
End Class
End Namespace然后我用VBC.EXE编译成一个control.dll文件,再写了一个hello.aspx文件调用,文件如下:
<%@ Register Tagprefix="davide" Namespace="mycontrols" assembly="mycontrol" %>
<html>
<body>
<davide:mycontrol runat="server"/>
</body>
</html>可是当我预览是报错,如下:
编译错误 
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误信息: BC30560: “mycontrol”在命名空间“mycontrols”中不明确。源错误: 行 2:  <html>
行 3:  <body>
行 4:  <davide:mycontrol runat="server"/>
行 5:  </body>
行 6:  </html>
 源文件: C:\Inetpub\ASP_NET\TMP7iy7hn2hbu.aspx    行: 4 请问这是错在那里呢?我是菜鸟来的,请各位多多指交!

解决方案 »

  1.   

    try this:
    do not use the same name both for your class and your filemycontrol.clslike this:
    Imports System
    Imports System.Web
    Imports System.Web.UI
    Namespace mycontrols
    public Class MyHelloWorldControl:Inherits Control
    protected overrides Sub Render(output as HtmlTextWriter)
    output.Write("hello worldW! davie")
    End Sub
    End Class
    End Namespaceyour .aspx file like this:
    <%@ Register Tagprefix="davide" Namespace="mycontrols" assembly="mycontrol" %>
    <html>
    <body>
    <davide:MyHelloWorldControlrunat="server"/>
    </body>
    </html>
      

  2.   

    oh,thanks!!!!!!!
    r you chinese???
    i want to make friends with you.
    do you have QQ or OICQ???