简体   繁体   English

在多个项目之间共享的ASP.Net用户控件

[英]ASP.Net User Controls shared between multiple projects

All, 所有,

My requirement is fairly simple. 我的要求很简单。 I have a asp.net page that I need to use in multiple projects. 我有一个需要在多个项目中使用的asp.net页面。 All the server controls and code behind needs to be the exact same on all projects. 在所有项目上,所有服务器控件和背后的代码都必须完全相同。 If I need to reuse the code and have one common point for the easier code maintenance what would be the best approach? 如果我需要重用代码并为简化代码维护提供一个共同点,那么最好的方法是什么?

User Controls - I created user controls out of the asp page and have a separate project with all the ascx files and code behind pages. 用户控件-我在asp页面之外创建了用户控件,并且有一个单独的项目,其中所有ascx文件和代码都位于页面后面。 Can I just add this project to a multiple solutions and then register the user control on a different project ? 我可以仅将这个项目添加到多个解决方案中,然后在另一个项目上注册用户控件吗? Is that possible? 那可能吗?

Use a usercontrol from another project to current webpage . 使用从另一个项目到当前网页的用户控件 The answer to this question has me confused. 这个问题的答案让我感到困惑。

Composite Controls - Is this even an option? 复合控件-这甚至是一种选择吗? Would I be able to pre-implement what a button inside the control does and not have to implement it in each page? 我是否可以预先实现控件内的某个按钮,而不必在每个页面中都实现它?

How does updating code work in each scenario? 更新代码在每种情况下如何工作? For user controls I would assume just rebuilding the project with the ascx files would do the trick ? 对于用户控件,我假设仅使用ascx文件重建项目就可以了吗?

PS: I have been trying and I did this which does not help. PS:我一直在尝试,但这样做没有帮助。

I have a project that has all the User Controls. 我有一个包含所有用户控件的项目。 Lets call it UserControls. 让我们称之为UserControls。 I have a test Web Project in which I have a new ASPX Page 我有一个测试Web项目,其中有一个新的ASPX页面

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TestControlsApp.WebForm1" %>
<%@ Register Assembly="UserControls" Namespace="UserControls" TagPrefix="SRC" %>

And the I use the user control as 我使用用户控件作为

<SRC:SelfRegisterControl ID="SR" runat="server"  />

The designer view says unknown tag, and the page renders blank. 设计器视图显示未知标签,页面呈现空白。

create a user control and register web.config file after that you can easily use in your project. 创建用户控件并注册web.config文件,之后您可以轻松地在项目中使用它。 After register in web.config no need to register in every page of your project. 在web.config中注册后,无需在项目的每个页面中进行注册。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM