Reputation: 359836
More specifically, what do I need to know about doing this in Visual Studio 2008 that's different from VS2005? I have found a decent number of references for doing this kind of thing in VS2005, such as
but even the Microsoft reference doesn't seem to say much about VS2008. This question stems from one I asked earlier, found here.
Going one step further, once I manage to build one of these assemblies (presumably a DLL), what would someone else need to do with my DLL in order include it (as a single page, or maybe sub-section) in their ASP.NET web site?
EDIT: Still more searching has turned up this, which looks a lot (but not exactly) like what I am trying to figure out. Either:
I hope this clarifies what I'm asking.
Upvotes: 2
Views: 1597
Reputation: 359836
I finally figured out how to do exactly what I need. It's laid out pretty nicely here (even though that article claims to apply to VS2005), but in the end it boils down to just a few things:
The biggest problem that I had before was that I build the user control inside of an ASP.NET Web Application instead of a Web Site. I spent so many hours banging my head against this, hopefully this answer will save at least one other new ASP.NET dev the hours of slogging through the terminology and subtle differences. Cheers!
Upvotes: 1
Reputation: 116977
All someone needs to do to use your UserControl is to add a reference to the .dll in their project, whether it's a web application or a web site.
Usually the best idea is to add it to a folder relative to your project (I usually use "_Libraries"), as you'll need to deploy it to its final destination.
EDIT:
I think perhaps I misunderstood the question. ASCX files aren't easily portable, because the UI layout is contained in the markup, not in the code.
If you wish a user control to be distributable, you should build the layout entirely in code either by constructing it by adding components to the Controls() collection of your usercontrol during the lifecycle (usually Init() or CreateChildControls()), or by overriding the Render() method.
Then anyone can just add one of your usercontrols by using a <@Register TagPrefix="mycontrols" namespace="My.UserControls" Assembly="My.UserControls" />
directive, and a <% mycontrols:mydropdownlist %>
asp tag to put it in their page.
Upvotes: 0
Reputation: 26956
This may seem like a silly question, but other than the nice design time interface, what benefits are you getting from having this as a User Control, rather than (the albeit more involved) method of writing a server control, which would give you exactly what you're asking for here - a simple way to deploy a control?
Assuming a CSS based approach to displaying the control, creating the actual control is fairly simple, using Panels for your containers (renders as a div), Labels, Literals, etc.
Some things need to be set at the correct point in the control lifecycle - e.g. you need to set the AssociatedControlId of a label to the ClientID of the input control, but this isn't set in CreateChildControls, you need to set it later.
Upvotes: 0