Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

Taking control of ASP .NET

Hi all,

I just started with ASP .NET and while I certainly like it for the possibilities it gives you when compared to ASP 3 and CGI programming I hate being stuck (it's been two weeks!) trying to find a way not to be driven by it's over-semplifications. By this I mean that almost all my time learning ASP .NET has been wasted trying to get rid of all the autogenerated crap and trying to understand all of the subtleties behind all those control properties and trying to take control of what I was doing. Just to make things more clear _I_ would like to program ASP .NET, not the other way around ;) I want to have full control of what is sent to the browser. The development speed that ASP .NET makes possible is already enough when compared to other frameworks... I don't want to drive a rocket, a fast car is good enough for me. One aspect of this means that I'd like to handle everything server-side (and maybe _later_ add a few javascript and ajax stuff where it makes sense for usability's sake). I don't care if I need to restore all the user input by hand in the Page_Init event. So my question is how do you handle this? I'm tired of all those books explaining me how to do websites dragging and dropping controls on a web form, that's not my style, I don't want to use the default out-of-the-box style of programming Visual Studio pushes to you. So my question is mainly about how (as a matter of style) do you code in ASP .NET, how do you restore user inputs, do you use HTMLControls instead of WebControls, where do you post your web forms to, if you use web forms at all, basically how do you prevent ASP .NET from doing what you didn't intend it to do?

Lorenzo Bolognini
Thursday, June 09, 2005

I know what you mean, all those "Teach yourself ASP.NET in 24 seconds" books miss the point really.

I use ASP.NET in VS.NET all day, every day and I have found that the best way to handle this is to have an essentially blank .aspx page and then override the Page methods in the code-behind page.

Then you can do just what you like, without all the extra twiddly bits getting in the way.

Here is the "HTML" view of the main page in the current web-application I'm working on:

<%@    Page

Obviously, the XyzPage class (which inherits from System.Web.UI.Page) does all the work, by overriding OnInit, OnLoad, Render, OnUnload, etc.

In my case, the structure of the page (i.e. which controls go where, data-binding rules, etc) is definied in a database. This data is fetched as the page is created and the resulting HTML, etc is rendered to the browser (in the Render override). This means that you only need one .aspx page (see above), which can "behave" as any of the thousands of possible pages in the system.

I really didn't want to have to create the 2000+ pages for this system, so I created just one generic one and stored the definition in the database. This has numerous advantages, including the fact that maintenance is trivial (well not really, but compared to keeping track of 2000 pages it is).

Of course, it depends what kind of thing you're working on. If you want a quick and dirty solution, then by all means do the drag-and-drop thing. But for me, I abandoned that after one day, in favour of being in control.

BTW, I love your analogy about wanting a fast car, not a rocket ;-)

Thursday, June 09, 2005
Thursday, June 09, 2005

I strongly encourage you to get a copy of Fritz Onion's book "Essential ASP.NET". It's the best second book you can possibly have on ASP.NET, and goes into lots of detail on the HTTP pipeline, what happens in page processing, and all the hooks you can use to take control of stuff.

aspx pages are only the very tip of the iceberg in ASP.NET.

Chris Tavares
Friday, June 10, 2005

Just had the chance to put my hands on Fritz Onion's book and read the 1st chapter which, alone, it's worth the price of the book!

Thanks both for your replies

Lorenzo Bolognini
Monday, June 13, 2005

*  Recent Topics

*  Fog Creek Home