<p>Suppose you have 2 different ASP.NET applications in IIS. Also, you have some ASCX controls that you want to share across these 2 applications.</p>

<p>What's the best way to create a "user control library", so that you can use the same control implementation in the 2 applications, withuot having to duplicate code?</p>

<p>Controls have ASCX with HTML + code behind.</p>

<hr>

<p>Composite controls will be difficult, because we work with designers who use the HTML syntax in the ASCX files to style the controls.</p>

<p>Tundey, we use SVN here. Do you have an example on how to implement your suggestion? How can SVN share the ASP.NET controls?</p>

<p>Thanks!</p>

[{'answer_id': 28055, 'author': 'Eric Z Beard', 'author_id': 1219, 'author_profile': 'https://Stackoverflow.com/users/1219', 'pm_score': 4, 'selected': True, 'text': '<p>You would need to create composite controls instead of .ASCX controls if you wanted to be able to use them in separate projects.</p>\n'}, {'answer_id': 28065, 'author': 'Tundey', 'author_id': 1453, 'author_profile': 'https://Stackoverflow.com/users/1453', 'pm_score': 1, 'selected': False, 'text': '<p>An alternative is to use your source control tool to "share" the ASCX controls between your webapps. This will allow you to make changes to the controls in either application and have the source control ensure the changes are reflected in the our webapps.</p>\n'}, {'answer_id': 28082, 'author': 'Tundey', 'author_id': 1453, 'author_profile': 'https://Stackoverflow.com/users/1453', 'pm_score': 0, 'selected': False, 'text': '<p>I use StarTeam here and it allows you to "share" objects (files, change requests, requirements etc) across multiple folders. Not sure if Subversion (SVN) has that feature. If it doesn\'t, here\'s another trick you can use: create a junction from the primary location of the controls to a location in the other projects. A junction is just like a Unix symbolic link. You can download the tool for creating junctions in Windows from <a href="http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx" rel="nofollow noreferrer">here</a></p>\n'}, {'answer_id': 28112, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 1, 'selected': False, 'text': '<p>The biggest problem I\'ve noticed with controls in ASP.Net is that you can\'t easily get designer support for both building the control <em>and</em> using the control in a site once you built it.  The only way I\'ve been able to do that is create an .ascx control with no code-behind (ie:  all the server-side code is in a script tag in the .ascx file with the runat="server" attribute).  </p>\n\n<p>But even then, you still have to copy the .ascx file around, so if you ever need to make a change that means updating the file at every location where you\'ve used it.  So yeah, make sure it\'s in source control.</p>\n'}, {'answer_id': 28142, 'author': 'EndangeredMassa', 'author_id': 106, 'author_profile': 'https://Stackoverflow.com/users/106', 'pm_score': 1, 'selected': False, 'text': '<p>I managed to do this by sacrificing some of the ease of building the controls in the first place.</p>\n\n<p>You can create a Control Library project that will generate a control library DLL for you. The drawback is that you have to create the controls with code only. In my last project, this was fine. In more complicated controls, this may be a problem.</p>\n\n<p>Here\'s an example:</p>\n\n<pre><code>&lt;DefaultProperty("Text"), ToolboxData("&lt;{0}:BreadCrumb runat=server /&gt;")&gt; _\nPublic Class BreadCrumb\n    WebControl\n\n    &lt;Bindable(True)&gt; _\n    Property Text() As String\n        \'...\'\n    End Property\n\n    Protected Overrides Sub RenderContents(output as HtmlTextWriter)\n        output.write(Text)\n    End Sub\n\n    Private Sub Page_Load(...) Handles MyBase.Load\n        \' Setup your breadcrumb and store the HTML output \'\n        \' in the Text property \'\n    End Sub\nEnd Class\n</code></pre>\n\n<p>Anything you put in that Text property will be rendered. </p>\n\n<p>Then, any controls you put in here can function just like any other control you use. Just import it into your Toolbox, make your registration reference, then plop it onto the ASP page.</p>\n'}, {'answer_id': 28229, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': False, 'text': '<p>Scott Guthrie gives some great advice here on how to set up a User Control Library project, then use pre-build events to copy the user controls into multiple projects. It works really well.</p>\n\n<p><a href="http://webproject.scottgu.com/CSharp/usercontrols/usercontrols.aspx" rel="noreferrer">http://webproject.scottgu.com/CSharp/usercontrols/usercontrols.aspx</a></p>\n'}, {'answer_id': 40875, 'author': 'Ant', 'author_id': 3709, 'author_profile': 'https://Stackoverflow.com/users/3709', 'pm_score': 0, 'selected': False, 'text': '<p>I recently did a web application that just referenced the files (about 90 in total) from one web application (aspx, master and ascx) without too much of an issue. That said I was using a heavily modified version of the <a href="http://polymorphicpodcast.com/shows/mv-patterns/" rel="nofollow noreferrer">MVP pattern</a>, a lot of interfaces and conventions to keep the complexity down, the same middle tier and one site was a subset of the other.</p>\n\n<p>Big issues:</p>\n\n<ol>\n<li>Master pages (and in turn designers and html view formatting) don’t work on a referenced file so you lose a lot of functionality. A pre-build step and a lot of svn:ignore entries was my hack around this. It was also a pain to get CruiseControl.NET to get the pre-build task to execute in the right folders.</li>\n<li>Shared pages/controls need to be extremely aware of what they touch and reference as to avoid bringing in extra dependencies.</li>\n<li>Both sites are locked together for deployment.</li>\n<li>I now have to pray that the maintainer reads my pokey little document about the mess I made. It’s so far outside of what I’ve seen in ASP.NET projects.</li>\n</ol>\n\n<p>I was under a massive time pressure to get it to work, it does and now both apps are in production. I wouldn’t recommend it but if you’re interested start at:</p>\n\n<blockquote>\n  <p><em>Add Existing Item</em>, select some files, click on the <em>Add</em> button’s arrow and say <em>Add as a Link</em>.</p>\n</blockquote>\n'}, {'answer_id': 374171, 'author': 'esteewhy', 'author_id': 35438, 'author_profile': 'https://Stackoverflow.com/users/35438', 'pm_score': 2, 'selected': False, 'text': '<p>In addition to what Tundey said, <strong>NTFS Link</strong> shell extension is helpful when it comes to sharing a large chunk of content (e.g.: a folder with .ascx/.aspx) between otherwise independent projects. In case of code, i think making another working copy from VCS is preferable.</p>\n'}, {'answer_id': 2146124, 'author': 'chugh97', 'author_id': 31750, 'author_profile': 'https://Stackoverflow.com/users/31750', 'pm_score': 2, 'selected': False, 'text': '<p>Have a look at this: <a href="http://www.codeproject.com/KB/aspnet/ASP2UserControlLibrary.aspx?msg=1782921" rel="nofollow noreferrer">http://www.codeproject.com/KB/aspnet/ASP2UserControlLibrary.aspx?msg=1782921</a></p>\n'}, {'answer_id': 14701656, 'author': 'shibin', 'author_id': 2042093, 'author_profile': 'https://Stackoverflow.com/users/2042093', 'pm_score': 0, 'selected': False, 'text': '<p>I have a suggestion.WE can use user control across multiples application by creating user control inside website project as normally.Then change the website property Use fixed naming and single page assemblies.Then we can use the user control dll into multiple applications.</p>\n'}]
['https://Stackoverflow.com/questions/28051', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2868/']