views:

1377

answers:

4

Our team is developing a rather big ASP.NET web project which initially startet in ASP.NET 1.0 and was ported several times to all new versions of .NET.

We made extensively use of User Controls (ascx). But in retrospect I doubt that it was a good decision. A very small percentage of these controls are reused (resuable) through different pages. There is only this layer of complexity added to the application making some things more complex.

For reusable, small and specialized controls we use Server Controls (inherited from the WebControl class), which work great.

So my question: starting a new project, is it okay to get rid of ascx and implement all in the pages themselves (aspx)? Maybe except if you do a lot of dynamical loading (we do not) of user controls? What is your experience and what would you advice?

+1  A: 

I would use usercontrols still, and mainly because you can disassociate content from design this way much more easily which will ultimately help a lot when you are changing the design of the application.

It also makes it a bit easier to move the controls around on the page than if you had to cut/paste code all over the place.

Mauro
+4  A: 

We have some projects which use ASCX controls extensively, and others that don't. In my experience you have to decide on a case by case basis.

My two favourite reasons for using ASCX controls are:

  1. You're implementing a piece of UI functionality which will appear on many different pages (or multiple times on the same page).
  2. You want to encapsulate some complex functionality to keep it distinct from the rest of the page, thus making your code easier to read and more maintainable.

ASCX controls can be useful, but you really need to make sure you only use them when there's a good reason to - otherwise - as you say, you can be adding unnecessary complexity into your codebase.

Chris Roberts
+1  A: 

It does purely come down to the type of web application which is being designed. At work one of our applications is very configurable so works on one page (default.aspx) and loads in controls depending on how its configured for the logged in user.

However, on the flip side, if you are writing a web site which needs to be accessed through SEO and has to be easy to navigate then implementing each view in an aspx page is a good way. Makes accessing each page during development easy and straight forward as you can access it directly (assuming no security permissions / logic get in the way) through setting it as your start up page in VS.

Another option to throw into the mix is using ASP.net MVC; interdependant views with re-usable usercontrols also thrown into the mix :-)

WestDiscGolf
+2  A: 

Used correctly, user controls improve maintenance and reusability, and very often are faster to create than server controls.

You mentioned that in your previous project, very few of the user controls were reused. This seems to be more related to poor planning than an inherent flaw in user controls themselves.

I guess a good rule of thumb would be to look at your design and see if you're using the same set of controls over and over again, in which case it does make sense to use user controls.

Thank you for your answer. You could call it poor planing, but it is a fact, that in our SPECIFIC web application the user controls were so specialized that in most cases are not required to be reused. Maybe there are other situations (e.g. portals) where user controls make much more sense.
splattne