Archive for June, 2007

29 Jun 2007

Maintaining Treeview State in Asp.Net 2 with a Sitemap

2 Comments C# Coding, Software Dev & Productivity

For a couple of days, I was looking around for a way to expand a treeview menu to the node you are currently on. On a site with nodes that go several levels deep, it is a pain to have to open all the nodes every time a postback occurs.

I found code samples online and followed so many goosechases. Some people put a marker in the session to let them know where their node was. Others tried to do some clever javascript which didn’t seem to work for me. It seems to be some code that is heavily in demand.

Finally, I found a blog post by Walt Ritscher which helped me get what I wanted in a few lines of code. It doesn’t maintain the state of all open and closed nodes on the tree, but it does open the tree to the node with the URL of the page you are on. It took me so long to find his blog post from last year, that I thought I would add another link here:

http://waltritscher.com/blog/ramblings/archive/2006/05/18/843.aspx

His examples are in VB.Net, but a conversion to c# is not difficult. Here are my code examples:

In the .aspx page:

<asp:TreeView ID=”TreeView1″ ExpandDepth=”0″ OnTreeNodeDataBound=”treeMainMenu_TreeNodeDataBound” PopulateNodesFromClient=”false” NodeWrap=”false” HoverNodeStyle-ForeColor=”green” HoverNodeStyle-Font-Underline=”true” NodeIndent=”10″ Height=”100%” runat=”server” DataSourceID=”SiteMapDataSource1″>

</asp:TreeView>

Notice the “OnTreeNodeDataBound” and “PopulateNodesFromClient” attributes.

In the code behind:

protected void treeMainMenu_TreeNodeDataBound (

Object sender,

System.Web.UI.WebControls.TreeNodeEventArgs e )

{

if (Request.Url.PathAndQuery == e.Node.NavigateUrl) {

e.Node.ExpandAll();

}

if (e.Node.NavigateUrl == “”) {

e.Node.SelectAction = TreeNodeSelectAction.Expand;

}

}

Anyway, thanks to Walt for his blog post. I looked over some other posts in his blog and found it very interested. You might want to have a look too.

27 Jun 2007

Live Earth on 7-7-07

No Comments Miscellaneous Rants

This is going to be a summer of music for me. Just weeks after successfully booking tickets to see Prince in London (they sold out after 30 minutes), we also came up in the lottery to see Live Earth at Wembley. It’s a good cause and I’m really excited about seeing the show.

Just a few more weeks. . .

23 Jun 2007

Driving Test Imposters

No Comments Bumblings

There’s a story in the news today about the growing problem of imposters sitting practical driving tests. Apparently, it’s possible to hire a look-alike to sit the test for you for just £500.

You can read the article here: http://news.bbc.co.uk/1/hi/uk/6231892.stm

When I came to England, I found the driving test very difficult to pass. I ended up taking it seven times over two years (and I had been driving for over ten years in the States). Each time I failed, the examiner would tell me how very close I was, “but sorry, you didn’t pass.” When I did pass the test, I got a license that doesn’t expire until I’m 70. No more tests. Even if we have flying cars in the year 2042, I won’t mind because my license will still be valid. Even in the States, you have to renew with a written exam every five years or so, but not here.

Now that I spend a lot of time riding around on a motorcycle, I see how drivers rarely look when they change lanes or signal when they enter roundabouts. They’ve established bad habits since they earned their license 20 or 30 or 50 years ago. It’s dangerous.

But, when road accident levels get too high, everyone jumps to the same conclusion—our tests are not difficult enough. They increase the difficulty. When I took the test in my late twenties, everyone said to me “I passed when I was 17, but it wasn’t so difficult then. I could never pass today.” Between the time I took my theory test for cars 6 years ago and the time I took the theory test for motorcycles two months ago, the DSA had attached an additional requirement—The Hazard Safety test. If you have a license already, you don’t have to take this test.

The roads are getting too dangerous so we take it out on 17 year-old kids who’ve never driven before by making sure they take their driving test over and over again. A 65 year-old man who took his test in the early 60′s if far more dangerous, I think. He’s the guy I worry about when riding my motorcycle.

No wonder people hire imposters to take their tests. I wish I knew about this scheme a few years ago.

23 Jun 2007

I’m a Firefox Convert — finally

No Comments Software Dev & Productivity

I finally switched to Firefox as my default browser this week. Despite the hype in the past, with Firefox 1.x I found too many sites which just didn’t render properly (due to web developers who didn’t code to standards). I also always work in corporate IE-only environments, so I always code and run with IE and do last-minute Firefox checks only if the project warrants it. The only reason I could see to use Firefox in the past was that it didn’t support Microsoft, but I found the quality of the browser lacking.

But this week I was building an ASP.net 2 app for a client and started to check things out in Firefox. I found everything rendered nearly identically. This way, I already had peace of mind about the code I was producing as I was building it (if it looked good in Mozilla, it will look in IE).

Firefox 2 seems to be a huge improvement over 1.x. I was really impressed.

I really started to appreciate Firefox when I started looking at the add-ons. There are hundreds of add-ons and themes written by the community that allow you to customise your browser exactly how you like it. A lot of the functionality is only coming into Windows with Vista and the sidebar, but it is still clunky. I like the add-ons best.

Here are some of the add-ons I’ve installed:

  • ForecastFox Enhanced — a weather update add-on which gives me up-to-date weather forecasts in the corner of the status bar (great for knowing what to wear on the motorcycle). Unlike the new weather gadgets in Vista, it allows you to set up separate profiles. When I’m at my client’s site, I choose their location and when I’m at home, I choose my own.
  • Del.ico.us Bookmarks ? I frequently bookmark something on my desktop but want to read the article on the laptop when I’m sitting on the couch later in the evening. I have to maintain two sets of bookmarks and it never works. With this add-on, it’s easier to use an online service like del.ico.us for all of my bookmarks (and I can have thousands).
  • FoxyTunes — I have a music add-on which interfaces with WMP so I don’t need to Alt-Tab each time I want to pause the music I’m listening to or skip to the next track.
  • Web Developer — superior to the developer Toolbar in IE.
  • Wizz RSS News Reader ? much better than the Feeds in IE7 and Outlook 2007 (which never stay in sync with each other on the same machine)

Anyway, I haven’t given up on Microsoft in any way. I still prefer Windows Media Player to iTunes (except where I need my iPod or for lookup up podcasts). But in browser terms, I’m going to give Firefox a go for a while.

<

20 Jun 2007

The Seduction of a Microsoft Access project

No Comments Uncategorized

The other day, I was asked a question I get asked on a lot of contacts: “How’s your Microsoft Access?” Then, with excitement, “we figure that you can knock up an Access application in just a few days compared with the weeks it will take for the other system.”

Another question I get asked on contracts is “We have an Access application that is in terrible shape. Can you help us create a SQL Server application based on it?”

I’ve moved away from Access for so many years now (“but they keep pulling me back in!”), but the VBA is still in my head. I may not be able to tell you the difference between Access 2002 and Access 2003, but I can code it just fine.

I’ve seen a lot of very big projects with Access at their core and I’ve seen a lot of very small projects where a developer insists on a full transactional Oracle solution. Access has its place, but there is a fine line to be observed.

The problem with Access is its apparent simplicity. When a project manager or a business user can slap together some forms and call it an application, they assume they can hand it to a developer and he will do the same thing as they did, but faster. A developer, however, will think about transactions, when the data is written to tables, how to control auditing and authentication, etc. In the end, you get an elaborate Access database application, but it may have been quicker to write it in C# or some other managed code.

The simplicity is also a problem because anyone can build an Access form. On 4 different contracts, I’ve been faced with a situation where a business user (and closet developer) “built” an access database which is now used by an entire company and can no longer take the strain. Since the database is usually not as normalised as it should be, it needs to be re-written on a more robust platform. I’ve done this a lot. And it always takes longer than it did to build the original Access database.

Access is a good tool. I know developers who would never ever touch it?even though haven’t explored everything it can do. Ask them to produce a one-user application, they’ll start designing SQL Server schemas and n-tier plans. I also know a developer who knows Access and VBA backwards and forwards but will not admit it when he’s in a contract.

As a report-writer and very generic application creator, Access is a very useful tool. For a seasoned developer, it’s definitely a step down.

We’ll see if I need to create another one this week.

19 Jun 2007

My job and my ride

No Comments Motorcycles

I’m in a new contract now for a small company about a forty-five minutes away. I’m primarily doing consulting on this one. I’m helping this company set up a distributed development environment with proper source code repositories and collaboration systems. I’m also doing some interface design. It’s a lot of fun, even without the coding.

The best part about the new job is that it gives me the oportunity to ride my motorcycle into work. I’ve had the bike for about a month now and love it. It’s a Honda CBF600. It can do 120mph easy (the guy at the dealership told me). I got it up to about 85 on a very straight and quiet rode and freeked myself out by going too fast. I’m not quite there yet. I’m also not at that “weaving though traffic” stage.

The most embarassing moment I’ve had so far with the new bike was coming up to a roundabout with an uneven road. When I put my foot down, I lost my balance and dropped the bike. I got my leg out from under it before it fell. When I tried to lift it, I grabbed it as if I would grab my bicycle—by the handlebars. I couldn’t lift it no matter how hard I tried. The guy in the car behind me (with a growing queue of traffic behind him) got out of his car and with a big smile on his face put one hand on the rear seat of the bike and one hand on the handlebars and lifted it easy. Now I know– I need to lift it like I’m lifting a heavy box and not like I’m lifting a bicycle. I bent the clutch and the gear shift, but no other damage was done. I was able to bend the gear shift back myself by taking it off and hammering it out and replaced the clutch for about £10. So, a learning experience. That bike is heavy.

Here’s a picture.

19 Jun 2007

PHP with Visual Studio

2 Comments Uncategorized

I’ve done some PHP projects in the past for a few clients and found it to be a pretty good language and very powerful. I used an application called HTML-Kit?which I think is pretty popular among PHP developers. It has no auto-complete or anything, but it worked better than notepad.

Now I’m all .Net and Visual Studio. Most hard-core Microsoft people I’ve worked with would never dream of touching php. “ASP is better, so why should I even bother trying PHP?” I expect PHP coders have the opposite argument.

However, I found a product that will let you code PHP in Visual Studio call VS.PHP. You can find the link here:

http://www.jcxsoftware.com/jcx/vsphp/home

I’m going to have to have a look at this.

03 Jun 2007

Reverend and the Makers

No Comments Miscellaneous Rants

I’m not very knowledgeable about popular music generally. I’m still very much and 80s man, I guess. However, in the UK I’ve been hearing a lot about Reverend and the Makers. I heard their song “Heavyweight Champion of the World” on Radio 1 this week and think its fantastic. It’s my new favourite video. I think it will get very big in the coming weeks.

03 Jun 2007

Ron Paul for President

No Comments Politics

As a long-time Republican, I have become extremely disillusioned with the current state of the party. The Neo-Conservatives have ruined the party and helped to discredit America all over the world. Living abroad as I do, I often see the hypocrisy of the current administration (who doesn’t?). I no longer consider myself a Republican—but I could never be a Democrat.

The war in Iraq is unjustifiable. Do 50% of Americans really still believe that Saddam Hussein had a part to play in September 11? After 4 years, the Republican presidential candidates are still talking about winning the war in Iraq. Except one.

Ron Paul is taking a lot of flak for speaking out about current foreign policy. It’s refreshing to hear someone talking about the war for what it is—a failed foreign policy.

Ron Paul doesn’t stand a chance of winning with the base of the party that votes in the primaries. He’s very popular on the internet, but not in the polls. Still, it’s nice to hear him say the things that need to be said. When he drops out, it will be time to start looki:ng at the Democrats, unfortunately.

Here’s a Youtube video from a CNN interview recently

03 Jun 2007

Scratch from MIT

No Comments Uncategorized

Last Sunday, the New York Times had an article about a software development language for kids 8 and over. It’s called Scratch. It can be found at http://scratch.mit.edu. We downloaded it last week and my kids have been making programmes throughout the week.

Basically, Scratch has a drag and drop interface that work like lego. You grab a block with an “if . . . then” and drag it onto your actions panel, then you drag other events (like “MouseOver”) and actions (like “Add n to X”) to fill in the blanks. It works surprising well and give a good introduction to software programming.

If you have kids, you should check this out.