ASP.Net User Controls shared between multiple projects

749 Views Asked by At

All,

My requirement is fairly simple. I have a asp.net page that I need to use in multiple projects. 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. 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 ?

PS: I have been trying and I did this which does not help.

I have a project that has all the User Controls. Lets call it UserControls. I have a test Web Project in which I have a new ASPX Page

<%@ 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.

1

There are 1 best solutions below

1
On

create a user control and register web.config file after that you can easily use in your project. After register in web.config no need to register in every page of your project.