一个有关自定义控件的简单问题,初学者

denghan 2003-10-16 06:12:45
项目名称:denghan
test1.aspx
-------------------------------------------------------
<%@ Register TagPrefix="SimpleControlSamples" Namespace="SimpleControlSamples" Assembly="SimpleControlSamplesVB" %>

<html>


<body>

<form method="POST" action="Simple.aspx" runat=server>

<SimpleControlSamples:SimpleVB id="MyControl" runat=server/>

</form>

</body>

</html>

test1.aspx.vb
------------------------------------------------
Imports System
Imports System.Web
Imports System.Web.UI

Namespace SimpleControlSamples

Public Class SimpleVB : Inherits Control

Protected Overrides Sub Render(Output As HtmlTextWriter)
Output.Write("<H2>欢迎使用控件开发!</H2>")
End Sub
End Class
End Namespace

之后按“生成”->"生成 denghan"后,在项目目录的bin子目录里看到denghan.dll文件。
“文件”-》"在浏览器中查看"出错:
分析器错误信息: 找不到文件或程序集名称“SimpleControlSamplesVB”,或找不到它的一个依赖项。

源错误:


行 1: <%@ Register TagPrefix="SimpleControlSamples" Namespace="SimpleControlSamples" Assembly="SimpleControlSamplesVB" %>
行 2:
行 3: <html>

我是初学者,弄了一个下午都没搞定,请高手们指教,百分感谢!
...全文
26 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
webdiyer 2003-10-17
  • 打赏
  • 举报
回复
注意两点就行了:
1、<%@ Register TagPrefix="SimpleControlSamples" Namespace="SimpleControlSamples" Assembly="denghan" %>中的 Assembly的值必须是你的控件所在的dll文件名,去掉后缀,比如你的控件编译后叫 myControl.dll,那么上面的Assembly的值就必须是 myControl ;
2、<SimpleControlSamples:SamplesVB id="MyControl" runat="server" />
中的SimpleControlSamples是你用上面的代码注册控件时的 TagPrefix 值,冒号后的SamplesVB 必须是你的控件的类名。
donger2000 2003-10-17
  • 打赏
  • 举报
回复
改为<%@ Register TagPrefix="SimpleControlSamples" Namespace="SimpleControlSamples" Assembly="denghan" %>后,这行不出错了,但新错又来了:
分析器错误信息: 未能从程序集 denghan, Version=1.0.1385.17725, Culture=neutral, PublicKeyToken=null 中加载类型 SimpleControlSamples.。


因为你的类名是: SimpleVB 而不是SamplesVB!
denghan 2003-10-17
  • 打赏
  • 举报
回复
把denghan.dll改名为SimpleControlSamples.dll后,上述错误没有了,但又出个“配置”错误:
分析器错误信息: 找到的名为“SimpleControlSamples”的程序集清单定义与程序集引用不匹配。

源错误:


行 170: <add assembly="System.Drawing, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
行 171: <add assembly="System.EnterpriseServices, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
行 172: <add assembly="*"/>
行 173: </assemblies>
行 174:


源文件: c:\windows\microsoft.net\framework\v1.0.3705\Config\machine.config 行: 172

denghan 2003-10-17
  • 打赏
  • 举报
回复
谢谢楼上各位的指导!
改为<%@ Register TagPrefix="SimpleControlSamples" Namespace="SimpleControlSamples" Assembly="denghan" %>后,这行不出错了,但新错又来了:
分析器错误信息: 未能从程序集 denghan, Version=1.0.1385.17725, Culture=neutral, PublicKeyToken=null 中加载类型 SimpleControlSamples.SamplesVB。

源错误:


行 3: <body>
行 4: <form method="POST" action="test1.aspx" runat="server" ID="Form1">
行 5: <SimpleControlSamples:SamplesVB id="MyControl" runat="server" />
行 6: </form>
行 7: </body>

源文件:.../denghan/test1.aspx 行5 .

这几天感冒+头痛,脑子不好使,请高手再帮看看,谢谢了
513 2003-10-16
  • 打赏
  • 举报
回复
你将用户控件文件拖到一个WebForm1.aspx,再用运行。
我这里也不能用浏览预览用户控件
donger2000 2003-10-16
  • 打赏
  • 举报
回复
如果不想改程序,那么把denghan.dll改成SimpleControlSamplesVB.dll吧
wzr20013309 2003-10-16
  • 打赏
  • 举报
回复
<%@ Register TagPrefix="SimpleControlSamples" Namespace="SimpleControlSamples" Assembly="SimpleControlSamplesVB" %>
<html>
<body>
<form method="POST" action="Simple.aspx" runat=server>
<SimpleControlSamples:SimpleControlSamplesVB id="MyControl" runat=server/>
saucer 2003-10-16
  • 打赏
  • 举报
回复
it works fine here, no need to change anything, just make sure SimpleControlSamplesVB.dll is the in bin subdirectory of your web page
zsww 2003-10-16
  • 打赏
  • 举报
回复
<%@ Register TagPrefix="SimpleControlSamples" Namespace="SimpleControlSamples" Assembly="denghan" %>


-------努力学习 不断实践 虚心讨教--------
sgsh51 2003-10-16
  • 打赏
  • 举报
回复
把SimpleControlSamplesVB.dll加入到项目中,
并设置项目依赖性即可
rgbcn 2003-10-16
  • 打赏
  • 举报
回复

<%@ Register TagPrefix="SimpleControlSamples" Namespace="SimpleControlSamples" Assembly="SimpleControlSamplesVB" %>

改成

<%@ Register TagPrefix="SimpleControlSamples" Namespace="SimpleControlSamples" Assembly="denghan" %>
tohen 2003-10-16
  • 打赏
  • 举报
回复
加入SimpleControlSamplesVB.dll
webdiyer 2003-10-16
  • 打赏
  • 举报
回复
<%@ Register TagPrefix="SimpleControlSamples" Namespace="SimpleControlSamples" Assembly="SimpleControlSamplesVB" %>

=========>

<%@ Register TagPrefix="SimpleControlSamples" Namespace="SimpleControlSamples" Assembly="denghan" %>
panyee 2003-10-16
  • 打赏
  • 举报
回复
SimpleControlSamplesVB是什么? 自己写的控件?
你没有SimpleControlSamplesVB.dll
donger2000 2003-10-16
  • 打赏
  • 举报
回复
Assembly="SimpleControlSamplesVB"
改成如下试试:
Assembly="denghan"

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧