可以拖动到 Visual Studio 设计视图中的自定义服务器控件
如何设置自定义服务器控件,以便将其拖动到 Visual Studio 中的设计视图中?
我创建了一个单独的 ASP.NET 服务器控件项目和一个自定义 MailLink
控件,基本上是通过复制此 MSDN 文章中的代码:如何:在 Visual Studio 中使用自定义 ASP.NET 服务器控件。 如果我手动注册库并使用以下两行将控件插入到我的网页中,则该控件工作正常:
<%@ Register Namespace="Samples.AspNet" TagPrefix="Sample" %>
<Sample:MailLink runat="server" />
但是如何注册/配置该控件,以便可以将其拖动到 Visual Studio 的设计视图中?如果我从解决方案资源管理器中拖动控件,我得到的只是控件的路径。 如果将服务器控件项目中的 dll 添加到我的 VS 工具箱,当我将控件拖到设计视图上时,我会收到剪贴板 FORMATETC 错误。
How do I setup a custom server control, so that it can be dragged into a design view in Visual Studio?
I have create a separate ASP.NET Server Control project and a custom MailLink
control, basically by copying the code from this MSDN article: How to: Use Custom ASP.NET Server Controls in Visual Studio. The control works fine, if I manually register the library and insert the control in my web page with these two lines:
<%@ Register Namespace="Samples.AspNet" TagPrefix="Sample" %>
<Sample:MailLink runat="server" />
But how do I register / configure the control, so that it can be dragged into a design view i Visual Studio? If I drag my control from the solution explorer all I get is the path to the control. If add the dll from the server control project to my VS toolbox I get a clipboard FORMATETC error when I drag the control onto the design view.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现这里的方法比 MSDN 更有用。
http://www.osnews.com/story/6802/Visual_Studio_NET_Design_View_and_Custom_Web_Controls
Here's a how to that I found more useful than the MSDN one.
http://www.osnews.com/story/6802/Visual_Studio_NET_Design_View_and_Custom_Web_Controls
这显示了如何处理它的逐步过程 http://www.newmobilecomputing .com/story/6802/Visual_Studio_NET_Design_View_and_Custom_Web_Controls/page4/
This shows a step by step process of how to handle it http://www.newmobilecomputing.com/story/6802/Visual_Studio_NET_Design_View_and_Custom_Web_Controls/page4/
只是为了确保我们意见一致:
您可以在 ASP.Net 中构建不止一种类型的控件。 不幸的是,根据您构建的控件类型,您通常只能在开发控件时或在开发控件时从 Visual Studio 获得控件的设计器支持。当您开发将使用该控件的页面时,但不是两者。 不受支持的控件将仅显示为灰色框。
在我看来,这是 Visual Studio/ASP.Net 的重大失败,但我离题了。 我已经看到通过使用没有代码隐藏的
ascx
控件克服了这个限制。现在一切都已经过去了,让我们继续前进吧。
在这种情况下,听起来您正在使用
服务器控件
。 您很幸运,因为当您构建使用该控件的页面时,服务器控件应该从 Visual Studio 获得设计器支持。 但是,您需要使该控件可供项目使用。服务器控件通常编译为 dll 程序集。 您必须在解决方案中包含对此文件的引用。 此时,您应该能够右键单击工具箱并选择
选择项目...
。 这将向您显示一个对话框,允许您选择程序集。 此时您的控件应该显示在工具箱中。不幸的是,Visual Studio 有时在添加这些控件方面可能会很奇怪。 您可能需要重新启动 Visual Studio 才能使它们可用。 请注意,我仍然使用 Visual Studio 2005,因此希望 2008 年这方面的情况有所改善。
Just to make sure we're on the same page:
There are more than one type of control you can build in ASP.Net. Unfortunately, depending on what kind of control you build you can normally only get designer support for a control from Visual Studio at either the time when you are developing the control, or the time you are developing the page where the control will be used, but not both. Controls that are not supported will just show up as grey boxes.
IMO this was a major failure of Visual Studio/ASP.Net, but I digress. I have seen this limit overcome by using an
ascx
control with no code-behind.Now that that's out of the way, let's move on.
It sounds like in this case you're working with a
Server Control
. You're in luck, because Server controls should get designer support from Visual Studio when you're building the page where the control is used. However, you need to make the control available to the project.Server controls are normally compiled down to a dll assembly. You must include a reference for this file in your solution. At this point you should be able to right click in your toolbox and select
Choose Items...
. This will present you with a dialog box that will allow you to select your assembly. At this point your controls should show up in the toolbox.Unfortunately, Visual Studio can at time be quirky about adding these controls. You may need to restart Visual Studio for them to be available. Note that I still use Visual Studio 2005, so hopefully things have improved in this respect for 2008.