从另一个项目到当前网页使用用户控件 [英] Use a usercontrol from another project to current webpage

查看:241
本文介绍了从另一个项目到当前网页使用用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个测试表单它是的 AspPage 的项目之下。然后我在的 TestUserControl 的项目3用户控件。是否可以注册/添加用户控件的网页?我曾见过一个教程,用户控件在pre编译复制,但它似乎我得到的错误,出版时无法正常工作。我AP preciate您的帮助球员。在此先感谢

I have created a test webform where it is under the AspPage Project. then I have 3 user controls in TestUserControl Project. Is it possible to register/add the user controls in the webpage? I have seen one tutorial where the user controls are copied in the pre compilation but it seems I get errors and that wouldn't work when published. I appreciate your help guys. Thanks in advance

推荐答案

基本上在ASP.NET用户控件不是设计不同的项目之间重复使用。这就是为什么如果你想拥有可重用的控件比你可以尝试创建您的控件上的CompositeControl或CompositeDataBoundControl基地。在这种情况下,您能够将您到类库项目控制,然后通过添加引用这个项目(组装)使用这些控件的其他标准服务器控件。在开发复合控件VS用户控件的主要区别是,你需要添加子控件编程,而不是使用标记。但主体是相同的。我建议从阅读一个速成班在ASP.NET控件开发入手:构建复合控制

Basically user controls in ASP.NET are not design to be reused between different project. That's why if you want to have reusable controls than you can try create your controls base on CompositeControl or CompositeDataBoundControl. In this case you will able to place your controls to Class Library project and then use these controls as other standard server controls by adding reference to this project(assembly). The main difference in development composite controls vs user controls is that you need to add child controls programmatically instead of using markup. But the principals are the same. I can advice to start from reading A Crash Course on ASP.NET Control Development: Building Composite Controls

这篇关于从另一个项目到当前网页使用用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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