Use a usercontrol from another project to current webpage

时间秒杀一切 提交于 2019-12-11 05:06:04

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/19286681/use-a-usercontrol-from-another-project-to-current-webpage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!