generating a dll of a web usercontrol - asp.net

How can I make a dll of my web application usercontrol?
I have usercontrol222.ascx, but I want to make a dll out of this usercontrol.

Create a project containing only your user control ("usercontrol222.ascx") and grab the control's dll from the deployment of your new project. Here's the source of this method with a more complete explanation: Turning an .ascx User Control into a Redistributable Custom Control (Notable excerpts below, see the link for the full run-down).
Step 3: Use the Publish Command to Precompile the Site
The next step is to use the new
Publish command to precompile your
site and turn your user control into a
potential custom control. You'll find
the command under Build / Publish Web
Site. In the Publish dialog, do the
following:
Pick a Target Location. This is the location on your hard drive that your
site will be precompiled to.
Deselect "Allow this precompiled site to be updatable". In updatable
mode, only the code behind file (if
any) would get compiled, and the ascx
would be left unprocessed. This is
useful in some scenarios, but is not
what you want here since you want the
resulting DLL to be self-contained.
Select "Use fixed naming and single page assemblies". This will guarantee
that your user control will be
compiled into a single assembly that
will have a name based on the ascx
file. If you don't check this option,
your user control could be compiled
together with other pages and user
controls (if you had some), and the
assembly would receive a random name
that would be more difficult to work
with.
Step 4: Finding the Resulting Custom Control
Now, using the Windows
Explorer or a command-line window,
let's go to the directory you
specified as the target so we can see
what was generated. You will see a
number of files there, but let's focus
on the one that is relevant to our
goal of turning the user control into
a custom control.
In the "bin" directory, you will find
a file named something like
App_Web_MyTestUC.ascx.cdcab7d2.dll.
You are basically done, as this file
is your user control transformed into
a custom control! The only thing
that's left to do is to actually use
it.

You cannot. User controls are for the simplified scenario where you do not want to create a custom control. They have the disadvantage that the .ascx file and any other artifacts (images, styles, etc) must be included in each web site that uses the user control.
If you need complete reuse between projects, then you need to create a custom control. That's not actually that hard, if you directly translate the user control into a custom control.

You may want to look at developing your own server controls. See the following similar discussion: ASP.NET Web User Control Library.

Related

Organizing ASP.NET Web Application Project

How do I update references to user controls after putting ascx and aspx files into different folders?
I'm not used to working with ASP.NET Web Forms projects, but I inherited this one. When I first received this Project, every file was directly under the root; no folders whatsoever. I've started putting files into folders and updating the paths.
When I try to load a user control, however, I get this error:
Cannot use a leading .. to exit above the top directory.
My user control is located at:
myProject\controls\Widget.asxc
My page is located at:
myProject\Pages\Activity\AST_Page.aspx
Markup from AST_Page.aspx:
<%# Register TagPrefix="tf" TagName="Cost" Src="..\..\controls\Widget.ascx" %>
My understanding is:
When a user navigates to AST_Page.aspx, the current path is myProject\Pages\Activity\.
Starting a path with ..\..\ should put me at myProject\.
Therefore, ..\..\controls\Widget.ascx actually points to myProject\controls\Widget.asxc.
My Project has access to my myProject\.
If I change ..\..\controls\Widget.ascx to ..\controls\Widget.ascx, I get a different error about not finding the file, which is expected as Widget.ascx is not under myProject\Pages\controls\.
There was a second issue on the page. I had "~/../../" in a src attribute; likely due to an aggressive find and replace.

How to show Project folders in browser

I m working in asp.net. I have created folders in my project folder and I want this to show on browser so that when users click on folder name it lists down all the files residing inside that folder.
Below i am attaching a picture which is a perfect example of what I want to do.
I have never done anything like this so i want guidance for this.
By default, if you enable Directory Browsing in IIS, a user can view like this -
However, it is not what you want in ASP.Net Application. Instead, you need to create a page with GridView or other data bound control, and bind it with Data.
If you want too fancy, you want to go with Commercial Components like Telerik FileExplorer.

two problems with Web Site type project (not Web Application)

I have a project which is a Web Site, not Web Application and have two problems because of that.
I have a custom control derived from BaseValidator which I had to put in the App_Code folder. Now on the page I want to register this control by
<%# Register tagname="mytagname" Namespace="PP" TagPrefix="dv2" %>
But when I get enter to this page, I have exception, because the src attribute is missing. I can't put in the src attr. path to the App_Code because I have another exception. How can I do that? This is a Web Site, so the sources are not compiled to one dll file, so I don't know what to add to the src attribute.
When I want to add to the Web Site a new project library, I have to compile it and manually copy the library dll file to the bin folder in the Web Site. But don't know, how can I debug this library with brakepoints?
This is my first time with Web Site project type. I always created the Web App.
1- Don't use tagname attribute here, tagname is suitable for UserControls.
http://msdn.microsoft.com/en-us/library/c76dd5k1.aspx
2- There is no any difference between using library in a web app or website. Just choose Add Reference from project node's context menu and select your class library from project tab.
Try creating a separate project for your CustomControls and reference it in your WebSite project by the namespace you use in your CutomControls project. Also check out this post for some information asp.net add custom control in website
Your second question, if you keep all of your projects in the same solution and just reference them to each other's projects, you will be able to debug and step into methods and set break points in any of the projects in your solution. If you don't want to do that, you have to copy the debug symbol files along with the .dll to the bin or point VS to where the necessary debug symbol files are located and then you will be able to step through the code in the .dll

Can you update a web user control without updating the entire site?

I have a website which uses a web user control... well, basically all over the place. It's even included in other web user controls.
So I thought I could just upload the new source and it would recompile on the fly and be fine, but instead every page or control that uses it complains about a type mismatch. Because it is used in so many places, it very quickly becomes easier to just update the entire website. (Or at least it would if I didn't need to go through our change management process for that...)
So is there something I'm missing? Isn't there any way to upload a web user control and have it recompile like when you update a single web page?
I think it is recompiling, it just takes a bit and you have a conflict with the mismatched .ascx and .ascx.cs files in Temporary ASP.NET Files while it recompiles. I could be wrong about this. Personally, I've had better success if I always upload both the .ascx and .ascx.cs files together.
I would think that if you pushed these items you should be good... any less and you might have issues:
bin contents - this will include your code changes to the user control and if the assembly version changes you will want to include any .dll that use it, I have run into issues to many times by trying to push just a single .dll that is in the bin.
.ascx file
I don't think you would need to push any other .aspx or .ascx files.

Is there a way to get rid of aspx placeholder files in a ASP.NET web deployment project?

I'm using a web deployment project in order to precompile my ASP.NET 3.5 web project. It creates a single extra DLL for the code in aspx and ascx files. And, for every aspx file there is a placeholder aspx file (empty) which needs to be copied to the server.
I'd like to simplify the deployment process. Is there a way (configuring the IIS site and adding some sort of http handlers etc.) to get rid of these aspx placeholders?
Also, I'd like to know if there is a way to get rid of the .compiled files in the bin folder. It would make the deployment process smoother.
Thanks!
I discovered it by myself. It is much easier than I thought (IIS 6.0):
In Internet Information Manager go to the property page of the site, then chose the tab "Home Directory" and click on the button "Configuration...".
Click "Edit..." for the .aspx ISAPI extension and uncheck "Verify that file exists". At this point, no aspx file is needed anymore.
Update
One important thing: I had to create an empty "default.aspx" file in the root of the application in order to allow the default document for requests like "http://www.example.com/" (without calling an aspx).
Update 2
Another very important thing: if you're using ASP.NET Ajax PageMethods, then you have to keep the aspx placeholder of that page. If you're omitting the file, a javascript 'PageMethods is undefined' error will be thrown on the browser.
IF it is possible, then it will require, at the least, the mapping in IIS of all possible requests to the asp.net engine. Not very difficult. Then, a HttpHandler should be possible to intercept all incoming requests. That handler should then be able to dynamically load compiled page classes and render them. You'd basically have a single engine DLL that serves page content.
But as you might have noticed from all the should's, it's not a simple thing to accomplish, and I doubt that it's really worth the trouble. What exactly is wrong with these placeholder files being present?

Resources