views:

750

answers:

3

After reading the answer here, I understand that, if I register a user control (I guess I'm really trying to use it as a custom server control) like this:

<%@ Register Assembly="MyDLL" Namespace="MyDLL" TagPrefix="myDLL" %>

Then only the codebehind is used, and the markup (.ascx) page is ignored. Why is this the case (it seems arbitrary), and how can I get around this problem without having to specify the Src="..." attribute in my Register directive? All I want to do is build a user control into a single assembly (a DLL) and hand that DLL off to another web site or web application project in such a way that the web site/app can use my user control. This should not be that hard, but apparently it is...

I am working in Visual Studio 2008, if it makes a difference.

Edit (prompted by the links in Rex's M's comments): it seems like most of the instructions for doing this kind of thing are applicable to VS2005, even the stuff on MSDN. My question is pretty much exactly stated here; is the answer provided on that thread correct

Is there any reliable, recent documentation describing this sort of thing for ASP.NET 3.5 and VS2008? I feel like using the latest versions is causing more confusion and difficulty than benefit.

A: 

It sounds like you want the functionality of a Custom Control. In a normal user control situation, the website needs an .ascx and that cannot be placed in a DLL.

Tejs
It certainly is possible to compile an ASCX to an assembly. See odetocode.com/Articles/417.aspx and http://msdn.microsoft.com/en-us/library/aa479318.aspx
Rex M
A: 

I strongly recommend to take a look at custom server controls. Since for the purpose of sharing controls over multiple projects they are better suited in my opinion than user-controls. User controls are better for internal reuse, within the same web application (i.e. on multiple pages).

Juri
+1  A: 

The thread you linked to is indeed correct. The information which originally addressed .NET 2.0 and VS 2005 is still very applicable. .NET 3.5 does not actually change .NET 2.0, just adds extra stuff. For things that are already in .NET 2.0, they are unchanged in 3.5.

Rex M
Why is it the case that I have to use a web site project and not a web application? A Web Application actually generates a single assembly when you build it, whereas (it looks like) I have to separately "publish" a Web site to generate a DLL. Other than that, I really don't get the difference (and I've read everything I could find on the difference between the two).
Matt Ball
First an important note: the ASP.NET markup you use in ASPX and ASCX is actually just another .NET language, like c# and VB.NET. It gets compiled into a class for you. The only difference is *when*. In a Web Application, it defers compiling the ASPX files to the server - e.g. they are compiled when IIS processes them. A Web Site is a different type of project geared specifically towards web sites, because it supports compiling everything ahead of time.
Rex M
One (hopefully last question): a VB2005 tutorial (http://webproject.scottgu.com/CSharp/UserControls/UserControls.aspx) I followed said that I should delete the web.config file in my user control project. Should I? Why/why not?
Matt Ball
@Matt the ScottGu tutorial you showed is not related to the discussion we've otherwise had. His method allows user controls to be reused in other projects *which you also control* by copying the ascx file into both projects.
Rex M
Awesome. The assumptions of that tutorial, in fact, do not apply to the problem I am working on solving. Unfortunately, I wasn't able to dig up anything that was more applicable. Anyway, Rex, THANK YOU. +1 many times over.
Matt Ball