The compilation options available in ASP.NET 2 are a bit overwhelming
compared to what's available now. I'm still struggling a bit to
get my head around it. I had some problems over the weekend on the
conversion I'm doing. I'm trying to get my personal site
converted over to ASP.NET 2. Amazingly, it's not the code that's
giving me problems as much as it is the new project structure and
compilation options. Scott Guthrie just
posted this
which answers at least some of the questions I have. But there is
definitely a bit of a learning curve involved here. Ironically enough,
people new to ASP.NET might actually have an easier time than those of
us who think we know what we're doing. So much has changed it's
going to take a bit of a mindset switch to really understand best
practices for different types of projects.
And now for the stunning conclusion of my 10 tips <g>
- Begin from the inside out
As a followup to tip#5 (move towards tableless formatting)...
It can be tough and intimidating to move away
from table-based formatting all at once. And there are still some
types of
layouts that are tough to do with divs. especially if you are just
getting started with CSS. Rather than giving up before you get
started, take some baby steps. An easy way to do this is to start with
your nested
tables first. There are plenty of instances where it is trivial
to
replace a table with a div structure, assuming you use static
widths. See how many nested tables you can replace with
structural HTML elements instead. Using a blend is better than
doing nothing at all. - Use percentage values for font sizes.
In the body or html style in your stylesheet, you can set your font to
a specific pixel (or
other unit of measure) size. Some people will even say you
shouldn’t
do that, but it seems like a decent compromise. Then in every
other style, set your font-size as it relates to that size. So
for instance, you might make <H1> 120%. Make
sure to say 100% if you want the same size. This makes it much
easier for your page to scale properly if people want to play with the
font sizes. Layouts also tend not to fall apart as easily.
One caveat to this, in certain nested style scenerios, your size will
be a percentage of the parent style, not the main font size, so keep
that in mind if something isn't working quite as you expected.
- Use inline styles sparingly.
The current version of Visual Studio uses inline styles a lot, which I
don’t like because it makes it tough to Cascade styles properly (the C
in CSS). There are a lot of tricks with cascading that people
don’t even realize you can do. Cascading often allows you to
build up a
consistent UI without a substantial amount of work and keep things more
consistent. In Visual Studio 2005, there is a move away from
those towards themes/skins. One example is the way you can skin
an ASP.NET control, like a datagrid, so that all your datagrid styles
can be consistent across your site and you don't have to format every
single grid. This is also a nice change in that what is left in
your datagrid control declaration are attributes that control the
function of the datagrid, like paging, datasource, etc. Makes it
much easier to see what's going on, once again separating function from
presentation. A good trend.
- Let go (more flow-based).
When you have the option, DON’T control the layout so much. See
where you can
get away with letting the page gracefully adjust to changes in browser
width, font sizes, etc. This also makes it easier to move towards
techniques like skinning or themes, which will be a big part of ASP
2.0. If you thought deciding what page width was best to support,
it's going to get tougher. People are going to be accessing your
site from phones, PDAs, their cars, their internet-enabled
fridges... Okay, maybe not that last one for awhile. But
you get the idea.
- Read up
There are tons of good resources on CSS, both online and in
books. You would be amazed at how much a bit of concentrated
study will teach you. I learned a ton from just the first 2
chapters of the Eric Meyer on CSS book. There are also plenty of cool
design sites pushing CSS. You can generally see
what they are doing using View Source and also by viewing the
stylesheet. Get the Web Developer Extension for Firefox. A good exercise is to take one of your current pages that uses table layout
and attempt to recreate it as closely as possible using only HTML
layout elements like divs and CSS. You'll be amazed at what you can learn rather quickly.
As I keep saying, there are a lot of things in Visual Studio 2005
that will help you move towards standards. I hope to get into
some specific examples in future posts.
Whenever I start talking about standards and CSS, the question is
inevitably – WHY? Isn’t what we are doing now good enough?
Isn’t it better to use tables for layout, after all Microsoft does it
and I know how to do it and I can get it done faster and all
that. It amazes me that the same people who would die if they had
to use traditional ASP again think nothing of using the same design
techniques they learned 5-10 years ago. And granted, Microsoft
tools have done nothing to help the situation and have actually hurt
the move towards standards and CSS. The Visual Studio IDE
combined with IE is a one-two punch that keeps a lot of developers
bogged down in old design patterns.
The good news is that the story gets a lot better with VS 2005 and
ASP.NET 2.0. All of a sudden we have a tool that doesn’t just
support standards, it helps you validate against them. It targets
cross-browser and cross-device support by default. All the web
controls are XHMTL-compliant. Hats off to the Web Tools team for
bucking the trend and giving developers the tools they need to move
into the next generation of web development. Here are some other
answers to the why question:
- Future proof – Future browsers are going to expect XHMTL markup.
Getting into stuff like AJAX is going to be a lot easier if you follow
standards. The expectations for a Web user interface is being
shaped by companies like Google. Things are going to start
getting much more complex.
- Maintainability – Which is easier, changing the height tag on a clear
gif on 100 pages or changing the padding in your stylesheet and watch
it fix the whole site? Once you have a site based on CSS, it
becomes much more trivial to adjust colors, formatting, visibility,
etc. And don’t get me started on trying to figure out a layout
problem when you are 15 tables deep into a nested table structure.
- Separate content from presentation – It becomes much easier
to edit the
content of your site if you aren’t digging through all kinds of extra
markup. Easier to do personalization and localization. Plus
it’s just good practice, along the lines of encapsulation that most
developers inherently understand.
- Accessibility – Easier access for people with disabilities, screen-readers have an easier time figuring out your content flow.
- All
the cool kids are doing it - Seriously, there are a lot of smart people
pushing this stuff, including people like Scott Guthrie on the ASP.NET
team. Sooner or later, people are going to start asking why you
aren't taking a standards approach, especially if you are a consultant
writing web applications for a living.
There are plenty of other good reasons, but those immediately leap to
mind. In the next few posts, I'm going to throw out some tips
about moving towards standards in your own development.
My girlfriend Kristin was bored at work a few weeks ago and decided to
Google me. She was surprised at the number of pages of listings (Google
has over 835 results for me). I reminded her that come to think of it,
I’ve been working online for over 10 years now. Hard to believe. Got me
thinking how all this got started….
My first job where I did anything with the web was at R.E.X. Music, a
small independent record label. I tried to start up an email list,
managed by hand at that point of course. I knew nothing of listservers
or anything that fancy. We also had a bit of web presence, but it was
hosted and managed elsewhere.
From there my next major job was with
SkillSearch Corporation, who had a resume database (pre-web). Around
the time I started there, they were realizing that the web was going to
make their main business obsolete, so they were trying some new stuff
online. When I first started, they had a simple website hosted and
designed by a web company out of, wait for it… Silicon Valley. This was
1996. My old boss used to boast about having the first career related
banner ad online through the now long defunct GNN service, which was
well on its way to getting its butt kicked by AOL.
I had played around with HTML a little bit and gradually started
digging into our site and was like “I can do this myself”. So I ended
up redesigning the site , we moved our hosting in house and I
eventually went on to do several generations of sites for a couple
different recruiting apps we had. You can still see some of my
“handiwork” in the Wayback Machine.
SkillSearch.com
At some point we wanted to do more dynamic sites and started using ASP,
VB components and SQL Server 6.5, believe it or not. SQL Server 7
had just been released and we quickly moved to that. I started
learning about databases and ASP code.
I started seeing the writing on the wall due to some business decisions
(SkillSearch was about to go under) and jumped ship to help out with a
new music eCommerce site for a music distributor in Nashville. I
was in a bit over my head at first, really writing VB components for
the first time and using MTS/COM+ Services. The architecture was
actually pretty good for the time, we were working with Billy Hollis’
old company and they had the web app thing figured out for the tools
they had to work with. So it was a good training ground for
me. My boss was also pretty open about letting me learn new
technology and be involved in the community. I jumped on .NET very
early and we were running our sites (both internal and external) on
.NET within a few months after the 1.0 release. I also got
involved more with the online community at that point, answering
questions on the ASP.NET forums and the old LearnASP lists and then the
ASPAdvice lists. I started blogging in early 2003.
All that to say, I've been involved with web apps for awhile now, but
we may just be entering another very interesting phase in the evolution
of the web and how we use it. In just the Microsoft world, between
ASP.NET 2.0 and AJAX, things are about to get very interesting.
We are going to start doing things with web applications that we just
couldn’t do before. As with any change, developers on the
Microsoft platform are going to find their world take on a different
appearance. All of a sudden standards matter and the toolset is
going to enforce and assist with that much better than before.
Having your app work with a variety of browsers and devices is going to
be expected. Through this blog I hope to share some things you
can start doing now to ease the transition and also talk about some of
the exciting things coming for web apps, particularly if you develop
using the Microsoft platform.