WTF - A Website I Visit Daily.

I was just visiting one of my favorite web sites this morning and it hit me that I should put the information here so that others interested in development might find this site also.

There is currently only one site that I wake up in the morning knowing that I am going to visit at some point during the day. Sometimes, 2 to 3 times a day. If you have never stumbled upon http://www.worsethanfailure.com, then I suggest you give it a try. The site posts articles daily about dreadful mistakes, oversights and just bad coding found as people use software, or most often when developers find that special nugget of code when maintaining some other developer's project.

The articles are a great break from the tedious software development process - including but not limited to - staring at your IDE all day, debugging, profiling and pulling your hair out or wishing there was some left. The guys that write the articles are very entertaining.

The content comes from developers that submit a chunk of offensive code or a great blunder that they have found in a dialog box or web page. I've submitted a few code blunders and a couple of those have been published.

Each article allows comments from anyone and often these are better than the articles themselves as other developers argue about the "right" way to accomplish what was done wrong in the article.

When I first found the site, it was www.thedailywtf.com. The owners decided to change the name to WorseThanFailure because in their words, it was hard to explain to his grandmother what WTF meant. I completely believe that the site had taken off and companies were willing to put paid advertising on the site, but were uncomfortable with the "WTF". So they found a way to keep WTF and give it a better name that fit easier in the corporate world.

Whatever the name, the content is great. Take a look when you get a chance. I hope you enjoy it as much as I have. It is a great read for that much needed break during the day.

Let me know what you think about it! And no, I have no connection with the site. I'm not affiliated with them in any way. I don't advertise on the site. I just enjoy it and think that if you are a developer, you will enjoy it also.

Cheers.

Trent Grandey
http://www.trentgrandey.com

Setting the Page Title from a Server Control

Earlier this week, I was working on a project and needed to find a way to set the title for the page from a control that was loaded programmatically onto an aspx page that was using a MasterPage. I knew how to set the page title from the child of the MasterPage (by adding it to the @Page definition), but that wasn't going to work. I needed a way to set that from a server control that was going to be loaded during the Page_Load event.

Here's the structure I was working with:

Article.aspx is a page that displays certain articles, based on the id passed in the QueryString. The Article.aspx page references main.master that provides the site layout.

In the Page_Load event in Article.aspx, the server control that actually renders the article is loaded with LoadControl(..) and the control is added to the placeholder on Article.aspx.

I wanted all the data access to happen in the control. I didn't want to have to make a call to the database from Article.aspx just to retrieve the title of the article. So I turned to Google as I often do. One of the first pages I came across was, not surprisingly, from 4 Guys From Rolla (http://aspnet.4guysfromrolla.com/articles/051006-1.aspx). I have found myself on the 4 Guys site many times and I usually come up with a great solution. It is a great reference site. But anyway, the article seemed to have exactly what I needed. I read through it and was a little dismayed. I was hoping for something a little more elegant than putting a runat=server in the HEAD tag of the master page.

The next page I visited was on .NET 247 (http://www.dotnet247.com/247reference/msgs/23/117737.aspx), another great reference site, although personally I get frustrated with the layout. This had another solution to pass variables between pages, but it was more complicated than I wanted as it was for a much different purpose.

After reading through a few more pages, I pieced together a solution. The control has a reference to the parent page, via this.Page. So after just trying it out, I found that the control could set the page title all the way up the chain with 

this.Page.Title = pageArticle.Title;

So I had my problem solved. I could go to the database just once to retrieve the article from the control where it made the most sense. I didn't have to jump through any hoops like exposing properties on the various pages and controls to get the data back and forth or having the head of the parent page become a server control. After quite a bit of digging, I was actually led to something that seemed so simple, I should have known it off the top of my head.

I was happy for a bit, until i realized that I wanted my site's name in the Title to, for SEO reasons. I could add that to the control, but that would sort of defeat the purpose of the "control" as it would now be bound to that site. So I turned to the master page, where it seemed most beneficial to have code that should be site-wide. I added a handler for the Page_PreRender event and added the following:

private void Page_PreRender(object sender, EventArgs e)
{
    if (!Page.Title.Contains("Web Security Tips"))
    {
        Page.Title += " - Web Security Tips";
    }
}

Now I've got my site's name in the Title of every page and I can set the rest of the title from whichever control I'm using to retrieve data for the current page.

I hope this helps. I know it isn't rocket science that I solved here, but sometimes the most obvious solutions can elude a developer when they are drilled into the process.

Trent Grandey

Programming Passion

I started my programming in a small class one summer given to advanced math students that had completed the 8th grade. The language was BASIC and the hardware was the TRS-80. Yes, I'm that old. I fell in love with computers that summer and I haven't been far from one very often since. The first computer that I owned was an Atari 400. Membrane keyboard, tape-drive and all. I quickly stepped up to the Atari 800 so I could run Microsoft BASIC, have a real keyboard and a floppy drive. After convincing my parents that I was really into the computer thing, they upgraded me to an Apple IIe. I thought I was in heaven. It was a "real" computer for the day.

In college, I did some Pascal classes that were taught in the lab on the VAX mainframe. I thought it was great that I could dial up from home on my 1200 Hayes Smartmodem and do my homework. After doing a few Pascal classes and a C class (they were just staring to come out with C+) I kinda dropped the programming. I actually changed from a computer science major to accounting. I still sat in front of a computer every day though. Eventually, while working for an accounting firm, I had an opportunity to go to work in a tech support department for a big software company. I was supporting an accounting program named DacEasy. I thought it was great that I could do accounting (which I loved) and get back to a computer job. Since then, I have never looked away from the computer monitor.

While working the 900 support line for DacEasy, I purchased a book to pass the time between calls. It was Sam's Publishing's Teach Yourself HTML in 7 days. I sat in the tech department and learned HTML from scratch. This was before WYSIWYG editing. I had notepad and a book on the syntax. IE wasn't around, it was all on Netscape 2.0. I fell in love with the web. I built a complete intranet for our support department and moved all our documentation online. An opportunity arose where I could leave Tech Support and take the new opening in Corporate Training. I was completely scared to do the training. I wasn't much of a public speaker. After all, I had been behind a computer monitor since the 6th grade. BUT, the guy who was leaving that position was also the guy who maintained the web site for DacEasy. I took the training job, just to have the extra job as webmaster. I actually liked the training much more than I thought I would and it was a great experience. But the true love was the web.

After doing the training gig for a while, there was a major management change at the parent company for DacEasy, Sage US Software. The parent owned 5 software product lines, DacEasy, Timeslips, TimeSheet Professional, Carpe Diem and TeleMagic. Out of the blue one day, the newly promoted CEO in charge of the whole thing, walked into my office as offered me a position as the dedicated webmaster for all the product lines. I was floored. I now had a full time job doing nothing but web site development. And it came with a great raise too!

Over the 5 years that I held that position, I taught myself JavaScript, then ASP and VBScript when it came out, then VB 6.0 to write COM objects for the ASP sites and just before I left the company when it moved from Dallas to Atlanta, I had just started reading about .NET. When the company closed the local offices, I stayed at home and taught myself C#.

That's how I progressed from a 6th grader to a .NET developer. I've written many web sites and even started a business with a retail software package. The software was a huge success, the partnership was not. I'm sure I'll discuss that first step into entrepreneurship in other entries, at least what the lawyers say I can discuss. After that blew up, I took a contract programming job with a local company. I had to make the switch from C# to VB.NET, but that wasn't too difficult. I still do work on that contract now. I'm also pursuing a few opportunities to get back into the retail software game.

I have often said that I can't imagine being a developer without having Google at my fingertips. I love reading about how to solve a problem or how to implement a new technology. I wish I had more time to just read about new stuff. And, I love reading "best practices" and "tips and tricks" articles. Hopefully, I'll get to give back to the community by opening up my own space here on the 'net. I have a lot of other interests, but programming has become a passion for me. I can't soak up all the information that I would like to. There's just so much out there to learn.