是否可以将Web用户控件添加到类库? [英] Is it possible to add a web user control to a class library?

查看:114
本文介绍了是否可以将Web用户控件添加到类库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑构建一些可重复使用的Web用户控件,但似乎无法在VS2008的类库中添加Web用户控件.有没有办法解决此问题,或者有更好的方法来创建可重用的控件?

I'm looking at building some web user controls with an eye toward re-use, but I can't seem to add a Web User Control in my class library in VS2008. Is there a way to work around this problem, or is there a better approach to creating reusable controls?

推荐答案

您可以创建 Web用户控件 Web自定义控件,以封装所需的功能.这两个控件之间的主要区别在于易于创建和在设计时易于使用.

You can create either Web User Controls or Web Custom Controls that encapsulate the functionality you need. The main difference between the two controls lies in ease of creation vs. ease of use at design time.

您也许应该考虑创建Web自定义控件库.有一个使用Web控件创建Web自定义控件的演练库模板.

You should maybe consider creating a Web Custom Control library. There is a walkthrough for creating a web custom control using the Web Control Library template.

根据MSDN文章" Web用户控件的建议VS. Web自定义控件",以下是两种控件之间的区别:

According to the MSDN article "Recommendations for Web User Controls vs. Web Custom Controls" these are the differences between the two types of controls:

网络用户控件很容易制作, 但使用起来可能不太方便 在高级方案中.您开发网络 用户控件几乎完全相同 开发Web窗体页面的方式. 像Web表单一样,用户控件可以是 在视觉设计师中创建的 可以用分开的代码编写 从HTML,他们可以处理 执行事件.

Web user controls are easy to make, but they can be less convenient to use in advanced scenarios. You develop Web user controls almost exactly the same way that you develop Web Forms pages. Like Web Forms, user controls can be created in the visual designer, they can be written with code separated from the HTML, and they can handle execution events.

但是,因为网络 用户控件是动态编译的 在运行时无法将它们添加到 工具箱,并以它们表示 通过一个简单的占位符字形,当 添加到页面.这使Web用户 如果您是,则很难使用控件 习惯使用完整的Visual Studio .NET 设计时支持,包括 属性窗口和设计视图 预览.

However, because Web user controls are compiled dynamically at run time they cannot be added to the Toolbox, and they are represented by a simple placeholder glyph when added to a page. This makes Web user controls harder to use if you are accustomed to full Visual Studio .NET design-time support, including the Properties window and Design view previews.

此外,分享的唯一途径 应用程序之间的用户控制 是在每个中放一个单独的副本 应用程序,这需要更多的时间 维护,如果您对 控制.

Also, the only way to share the user control between applications is to put a separate copy in each application, which takes more maintenance if you make changes to the control.

网络自定义控件是已编译的代码, 这使它们更易于使用,但 更难以创建;网路自订 控件必须使用代码编写. 创建控件后, 但是,您可以将其添加到工具箱 并在视觉设计师中展示 具有完整的属性"窗口支持 和所有其他设计时功能 ASP.NET服务器控件.

Web custom controls are compiled code, which makes them easier to use but more difficult to create; Web custom controls must be authored in code. Once you have created the control, however, you can add it to the Toolbox and display it in a visual designer with full Properties window support and all the other design-time features of ASP.NET server controls.

此外,您可以安装一个 Web自定义控件的副本 全局程序集缓存并共享 在应用程序之间,这使得 维护更容易.欲了解更多 有关信息,请参阅全局程序集缓存.

In addition, you can install a single copy of the Web custom control in the global assembly cache and share it between applications, which makes maintenance easier. For more information see global assembly cache.

这篇关于是否可以将Web用户控件添加到类库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆