Delta Engine Blog

AI, Robotics, multiplatform game development and Strict programming language

Reusing ascx web controls

After developing and testing some ascx web controls in the past I was woundering why I have to copy them over to a new web project today instead of just referencing them. When you write a normal windows application and then want to reuse some library parts in another project (or if you just want to structurize your app a little bit better) you would obviously use a dll library for the job to share functionality.

Not that easy with web controls. My first thought was just to copy the .ascx and .ascx.cs files over to a new dll project and start compiling. After adding the missing images and scripts the following thing happend:



Well, the code does compile on a website, but in a dll project it will not build the ascx code for you and merge the controls defined there with your .cs file. If you do not define controls or do any visual stuff you can probably just use WebControls instead of UserControls, but you still have to implement the Render method yourself and you just do not have any design support. More information about creating server controls can be found here.

While that solution is probably the cleanest one and has the advantage of hidding the source code and make it easy to just drag and drop controls on your page, it is the hardest to develop. And I already have my .ascx controls working, I just want them in another project without copying them over again and again.

I searched for a while on the web for some solutions, see below for all the links. The best solution for me was the one from ScottGu, which just uses a normal website and then uses a post build copy to get all the files into your current website project. The controls dummy website can then be used all over the place, you just have to add the copy command to each website that should use your controls. This solution might not be the best, so if you have more complex problems, check out the links below.

No reason to repeat all the stuff ScottGu has already written, check out his great article here or here.

BTW: I use this just for simpler web controls or when I have something that needs to be duplicated on some pages. For Ajax controls on the other hand I got a project similar to the AjaxControlToolkit, but there you live without design time editors anyway.

Links:

Comments (2) -

  • cep oyun indir

    5/5/2010 12:24:42 PM |

    Wow! what an idea ! What a concept ! Beautiful .. Amazing ?

  • extended auto warranty advantages

    5/14/2010 8:17:34 PM |

    Your website is really useful for many people I think. You helped  me in various situations because I many times I have found the useful information which was really important for me in your site. Reading this your post I have known many new things about the  ascx web controls which I have not known before. It is really great that you share for us such useful stuff. Thanks a lot one more time for the useful information and I will be waiting for more great news from you in the nearest future.

Comments are closed