| Date: | 2008-08-07 12:55 |
| Subject: | CSS class selectors |
| Security: | Public |
| Mood: | sleepy |
I found out something new yesterday whilst working how I could implement a styling thing on the web site I'm working on. I have some item on the page with one of two CSS classed applied to given them a particular background image:
<div class="foo"> ... </div> <div class="bar"> ... </div> <div class="bar"> ... </div> <div class="foo"> ... </div>
I've also got some javascript to add styles on top to either the first two or the last two elements depending on some criteria. I wanted to add those extra styles via another class because that was easier than adding a whole bunch of styles individually. Hence so when you press a button we might end up with
<div class="foo weeble"> ... </div> <div class="bar weeble"> ... </div> <div class="bar"> ... </div> <div class="foo"> ... </div>
The question was how to add a CSS selector to match those above.
Now I knew that if you have multiple classes in a given element both styles would be applied hence with the following CSS file
.foo {background-color:red} .bar {background-color:green} .weeble {border:1px solid black}
Then the top two <div>s would have a border around them.
What if the weeble class set a background colour:
.foo {background-color:red} .bar {background-color:green} .weeble {background-color:orange}
well, then the above <div>s would be* orange, orange, green, red - if two rules apply (e.g. .foo and .weeble) then specificity* comes into play, in this case both rules are equally specific (they contain one class specifier) so then it is a case of last one wins.
This is all well and good but what I wanted was that adding class weeble would alter the existing colour - foo items would be light red, bar items would be light green. I couldn't use
.foo {background-color:red} .bar {background-color:green} .foo .weeble {background-color:#f99} .bar .weeble {background-color:#9f9}
because a space in the selector means contains - "an item with class weeble which is within an item with class foo". Similarly I couldn't use all the other selector modifiers I knew - comma is or, < is child, + is adjacent sibling.
So I went back to the specs** and had a further look whereupon I saw that there is a selector to match multiple classes and that is to append on another full stop - ".foo.weeble" matches elements which have both class "foo" and "weeble" applied. I'd not picked up on that when I read the specs before so that was a nice find.
Hence using a style sheet of
.foo {background-color:red} .bar {background-color:green} .foo.weeble {background-color:#f99} .bar.weeble {background-color:#9f9}
means that I can use javascript to add a class of weeble to existing elements to lighten their current colour, whether that colour be red or green.
Though there is a sting in the tail ... this worked fine with Firefox and IE7 but it didn't work with IE6. Oh and Visual Studio 2005 gives me errors saying that my CSS file is wrong.
* http://www.w3.org/TR/CSS21/cascade.html#specificity
** http://www.w3.org/TR/CSS21/selector.html#class-html
post a comment
| Date: | 2008-08-04 12:45 |
| Subject: | Yet another database programming framework |
| Security: | Public |
| Mood: | busy |
Visual Studio and .NET Framework 3.5 SP1 is out soon (http://www.theregister.co.uk/2008/08/01/visual_studio/) and "According to Ellison-Taylor, the SP introduces an ADO entity framework that let's you program using high-level objects".
It used to be a joke that with every version of Visual Studio would come with a new way of talking to databases* ... now MS aren't even waiting for a new version, we're getting a new database programming technique with a service pack!
Oh and yes I know I've not been blogging very much of late; it's mostly 'cos I've been 100% busy at work** - when I'm not coding the things on my TODO list I'm helping others code their stuff - but also 'cos I'm learning mostly about our framework at work and that's stuff to be written about on our work's wiki site not this blog***.
But I have been learning about templated ASP.NET controls and I really should write that down before I forget it all :-) ... it's just the case of finding the time...
* DAO, RDO, OBDCDirect, ADO, ADO.NET.
** And enjoying every minute of it
*** It would be neither appropriate or interesting to blog here
post a comment
| Date: | 2008-07-16 17:59 |
| Subject: | Footie |
| Security: | Public |
| Mood: | sore |
Played footie today, first time in three and a half months*, played for an hour rather than the usual 45 mins, stayed out of goal** which meant I didn't get any rest and it was a warm and sunny day ... and now my legs are rather tired and sore.
But it was fun and I'm looking forward to getting my fitness back again
* ripped tendon in finger meaning no footie of course ** finger is still not 100% fixed
post a comment
| Date: | 2008-07-03 13:52 |
| Subject: | solar-powered snails |
| Security: | Public |
| Mood: | juggling |
There is a story here about dumb questions asked in school science exams and well they certainly seem more like questions on common sense than science.
But now I'm intrigued about the question "What powers a solar-powered snail?", I mean what is a solar-powered snail; can't say I've every seen one. Better still, if you sat the exam and didn't necessarily care about getting the "right" answer think of the fun your could have...
Q. "What powers a solar-powered snail?". A. Electricity ... assuming the solar-power is used to charge a battery to provide energy for the snail the snail itself is powered by electricity. A. Global warming ... why would someone build a solar powered snail, perhaps to test and improve technology for building miniature solar cells and associated motors, and the need to improve solar technology at the moment is currently driven by the threat of global warming. A. Leaves ... the concept of a snail attached to an electric motor powered by a battery attached to a solar-panel is frankly nonsense but a snail powered by energy derived from eating leaves which themselves grow using solar power (photosynthesis) isn't - meaning the snail is only indirectly powered by solar power but is directly powered by digesting leaves. A. Sex ... assuming you could interview the snail and ask them "what drives you in life" they would most likely say sex, their offspring or similar.
post a comment
| Date: | 2008-06-27 21:31 |
| Subject: | Google street car |
| Security: | Public |
| Mood: | shattered |
Was in a meeting today when I was distracted by a weird car go past the window, it had what looked like cameras mounted on a pole on the roof, so I'm guessing it's the car Google uses for it's street view. That should be interesting 'cos our windows at work are mirrored so the street view will end up being a view of the weird looking car.
post a comment
| Date: | 2008-05-24 22:53 |
| Subject: | Javascript success |
| Security: | Public |
| Mood: | okay |
Looking through my old blog.txt just now - I tend to write bits down in a text file until I get the time to polish and update my blog - found I'd forgot finish off and upload this blog about this bit of javascript I wrote a while back...
I'm quite pleased with a bit of javascript I've written this week. I needed to format data entry fields as currency so I wrote some code to loop through all the input elements on the page (document.getElementsByTagName) searching for those with a class of "currency"*. From there I hooked into each of their onBlur event handlers (using $AddHandler**) to trigger some code that would add in a currency symbol and thousand separators. Unfortunately the server-side data binding I was using couldn't cope with the formatting - the formatting was just for show on the page*** - so I also hooked into the onSubmit event handler of the form to trigger some code to remove formatting. All good stuff.
However, then there is the issue of AutoPostBack. This is a feature of ASP.NET web controls whereby they render some javascript to submit the form when their onChange event fires. It's used in the, very common, example of the user changing their selection in a dropdown list and having the page immediately submit itself; rather than waiting for the user to press a "Go" button for example****. To submit the form the control calls __doPostBack which in turns calls the submit(); method of the form.
The only thing is, the submit(); method does not trigger the onSubmit event. Dunno why, seems counterintuitive to me, always has, but this has been this way since the beginning of javascript in the browser. This meant my unformatting code won't trigger when using AutoPostBack.
Luckily javascript is really cool - functions are objects and function names are really references to the function obejcts. Hence it's easy to point the reference for __doPostBack(); at my code and assign a new reference to the original code:
if (window.__doPostBack) { window.___doPostBack = window.__doPostBack; window.__doPostBack = window.my__doPostBack; }
function my__doPostBack(target, args) { // call code to do unformatting ___doPostBack(target, args) }
I had this working a while ago but this week I added another layer of complication; I wanted to shove the whole thing inside an ASP.NET UpdatePanel to smooth out all the postbacks going on. Updatepanels don't do a "normal" submit, they do an xmlHttpRequest Ajax-style request. Hence I need to hook into yet another submission route.
Luckily Microsoft's PageRequestManager which takes wraps the xmlHttpRequest Ajax-style request provides a whole lot of functionality, including the beginRequest event - so that I could remove the formatting before sending the request - and pageLoaded - so that I could add the formatting when the data comes back again.
if (Sys && Sys.WebForms && Sys.WebForms.PageRequestManager) { Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(unformatCurrency); Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(formatCurrency); }
What I find pleasing about this is how easy it was, the ASP.NET frameworks are quite flexible with numerous places to hook into so that you can "do your stuff"
* The other option would have been to use prototype's document.getelementsbyclassname method or even wait for FireFox3 ** Again I could have used the equivalent in prototype, or even the IE / W3C DOM native methods, but I chose $AddHandler 'cos I knew in the future I'd be using MS ASP.NET AJAX on the site. *** Well it's a good idea to make it clear to the user what they've typed in 'cos it's easy to type 1000000 when you mean 100000 and not spot it. **** Though it is good practice to always provide a "Go" button as well in case the user has turned off javascript in their browser.
post a comment
| Date: | 2008-05-24 22:13 |
| Subject: | dance the chiki chiki |
| Security: | Public |
| Mood: | okay |
Didn't watch Eurovision this year but did see the bit of the end where they show quick clips of them all and this one http://www.bbc.co.uk/eurovision/participants/spain.shtml is definitely the best song of the lot.
Shows the Spanish have a good sense of humour. Eurovision should definitely be about humour, which is why I likes the Lithuanian song of two years ago. Is it me or does the guy in the video who goes crazy 1min 15sec into the song, remind you of Steve Ballmer
Actually, the voting of that song was quite interesting; some countries gave it high marks (8,10,120 others nothing (nill points) - to me that indicated those countries that 'got' / appreciated irony and those that didn't.
UPDATE: Proof that, you name it and there'll be a wikipedia page about it.
And following that you can find the translated lyrics which states that " 'Perrea' literally means 'shag' in slang" which means the Spanish chose a song that starts with the line "shag shag" ... superb.
post a comment
| Date: | 2008-05-22 15:00 |
| Subject: | Telekinesis |
| Security: | Public |
| Mood: | good |
My finger is out of the splint and it's all perfectly straight :-)
Only that's the thing, it's perfectly straight even when I try to bend it! In fact trying to bend it feels very weird, I concentrate hard and nothing happens! I stand as much chance of moving it via telekinesis.
Still it is only just out of the splint and so nothing to worry about yet and I've got some physio booked next week so that should help.
post a comment
| Date: | 2008-05-18 14:33 |
| Subject: | quite superb |
| Security: | Public |
| Mood: | continuously sleepy |
Saw this advert on the tele yesterday and it is quite superb ... so I knew it would be up on YouTube somewhere.
post a comment
| Date: | 2008-05-14 18:14 |
| Subject: | VS 2008 and .NET 3.5 SP1 |
| Security: | Public |
| Mood: | busy busy |
Wow, that's a lot of updates
In other news got notification of hospital appointment today; the splint will hopefully be coming off my finger* next Thursday.
* http://www.blurty.com/talkread.bml?journal=webgeek&itemid=87126
post a comment
| Date: | 2008-05-06 18:27 |
| Subject: | Read all the documentation... |
| Security: | Public |
| Mood: | tired eyes |
I've been working with the CascadingDropDown Extender today. Ha d little problem when hooking it up to the back end web service as I got a "[Method error 12030]" error message back.
After a spot of googling I found a few people had had this error but there weren't any clear answers. Then I was a bit worried at first when I found a explanation for the problem as being due to the way IE6 handles network connections. That didn't look very promising for my chances to resolve the problem in the time that I had.
But then I did some more googling and found the error raised on CodePlex which gave a hint of
"Please make sure that if this is a page method then it has the ScriptMethod attribute. If it is a webservice then it should have ScriptService attribute."
and lo and behold I'd remembered all the ScriptMethod attribute but not the ScriptService one.
post a comment
| Date: | 2008-05-06 18:24 |
| Subject: | Beware of sporks |
| Security: | Public |
| Mood: | tired eyes |
From here http://www.xkcd.org/419/

post a comment
| Date: | 2008-05-01 18:15 |
| Subject: | Tribuite to Father Ted |
| Security: | Public |
| Mood: | laughing / sleepy |
At work we've had a few tunes going through our head, the other week it was the web song "Magical Trevor". Then it was the song from Portal. This week it has been the song from Father Ted "My Lovely Horse".
The only problem is that these songs are too catchy and go round and round you head until the next song displaces them. And last night I couldn't get to sleep because the song kept going round my head*. Grrrr....
What was worse was someone made a joke at work about "My lovely spork" because I had a spork left over from lunch the other week still on my desk. So last night my brain** kept thinking what would be the lyrics to "My lovely spork". This is what I came up with (to the tune of My Lovely Horse)
My lovely spork Feeding me my food Where would I be Without your spoon shaped bit And your prongs
I want to eat melon chunks with you That I bought from Marks and Spencer’s Then spoon up all the juice that’s left ‘Cos fresh fruit is expensive
My lovely spork You’re neither spoon nor a fork You’re the best of both You’re the best of both You’re a spoon and a fork
* And the high from having seen Chelsea win through to the European Championship finals.
** And it was my brain and not me
post a comment
| Date: | 2008-05-01 18:08 |
| Subject: | Laying out tables nicely |
| Security: | Public |
| Mood: | good |
On my current development project we've needed to layout multiple (separate) tables of data on the same page and needed to get them all to line up nicely. After trying to get the tables to behave I decided the only way to be sure* was to use the CSS style table-layout:fixed whereby the browser's table rendering engine sets the widths on columns based on the <col> specifications you give or the widths of the cells in the first row. So by doing
<table> <col style="width:..." > <col style="width:..." > <col style="width:..." > <...> <tbody> <...> </tbody> <table>
for each of the tables on the page I could get all of the tables to have the same column widths and line up nicely.
Only today I was rather disappointed to read that I can't do this with ASP.NET controls, to quote "You cannot have an HtmlTable control with nested ..., <col>, ... elements". And worse "An exception will be thrown if you attempt to programmatically add these table model elements to the ... HtmlTable control".
Grrrr....
* Other than taking off and nuking the site from orbit
post a comment
| Date: | 2008-04-09 18:18 |
| Subject: | |
| Security: | Public |
| Mood: | okay |
After seeing pictures in the paper where people have made Excel graphs to indicate song lyrics, I thought I'd do my own:

post a comment
| Date: | 2008-04-09 18:05 |
| Subject: | Red Arrows |
| Security: | Public |
| Mood: | accomplished |
Just got round to uploading photos I took of the Red Arrow fly past last week

P.S. Got my XML working and it works a treat.
post a comment
| Date: | 2008-04-09 10:18 |
| Subject: | Nearly there... |
| Security: | Public |
| Mood: | tinkering |
Yesterday - and now today too - I've been rationalising an XML file which has grown to configure several tasks and hence was getting in a little bit of a mess with data being repeated in many places. I've also been refactoring my code which exposes the XML file as a DataSourceControl.
Only the more I tinker the more this reminds me of a particular Father Ted sketch
post a comment
| Date: | 2008-04-04 12:56 |
| Subject: | Docking Computer |
| Security: | Public |
| Mood: | busy |
Having just read about the Jules Verne module docking with the ISS it reminds me of the docking computer you could but for your ship in the computer game Elite I used to play** when I was a kid
* In fact I played it a lot during one summer where I doubt I saw much sunshine
post a comment
| Date: | 2008-04-02 22:21 |
| Subject: | why it's good to be ambidextrous |
| Security: | Public |
| Mood: | sore |
today at football one of the opposition fired in a beautiful shot on goal. i was in goal and saw - well actually i think my sub-concious saw - the ball fly at my face and i raised my hands to save the ball - well actually to save my face - which i did to shouts of "nice save"*
only then i looked at my middle finger of my right hand which was stinging a bit, and, well, it wasn't the shape it ought to be: the first knuckle was straight but the upper knuckle was bent at 45 degrees. fingers don't make that shape normally. it didn't hurt and i could straighten it with my other hand, but when i let go i went bent again.
the lads saw it and thought it might be dislocated so one of them took me to the first aid bod and at that point i started feeling queezy - i think i was fine until my brain kicked in and thought about the concept of dislocation and pain and then pumped out loads of adrenalin which raised my anxiety levels. first aid bod got me a sling and mate got me some water and i was fine again, well except for a bent finger.
one of my colleagues took me to A&E where they x-rayed me; it wasn't broken or dislocated but i'd torn the tendon. apparently it's called mallet finger (warning there is a photo of it on that link). it didn't hurt other than throbbing but i was squeemish when the doctor said he was going to straighten it - it's really odd when you see you finger at an angle you know you can't - or at least shouldn't be able to - bend it to.
the doctor put it in a splint and said it could take up to six weeks to mend and the mean time i should rest it as much as possible, keep it elevated to relieve the swelling and be sure to keep it straight if i take the splint off**. so for the next six weeks i will be mostly left handed, i'm typing this now left handed. luckily i'm slightly ambidextrous - i use a knife and fork as a left handed person would, i can play badminton left handed***, and i try sometimes to play pool left handed too*** - so hopefully i'll cope ok.
ironically i was talking with a mate on the weekend about being ambidextrous, talking about encouraging kids to use either hands to catch as they grow up to help them be more versatile and now i find myself being a case in point :-)
* had a laugh with the first aid bod what happened and he asked "did you save the goal" and i said "yes, even though the ball was flying at pace" and he said "well that's what matters" and then wrote in the accident report "spectacular save" :-)
** according to a mate this is because it could tear again before it's healed, ouch!
*** though i can't serve left handed at all
**** and i'm more left footed than right
post a comment
| Date: | 2008-03-26 18:21 |
| Subject: | Nothing to see here |
| Security: | Public |
| Mood: | fine |
The ASP.NET GridView supports an <EmptyDataTemplate> to show when there is no data, your parameters on your data source control may not have found any matching data. However there isn't an <EmptyDataTemplate> on the repeater control and it's not obvious if there ever will be*
A quick google reveals that others have fixes, e.g. http://weblogs.asp.net/acampbell/archive/2004/04/02/106166.aspx fixed this ages ago and then this http://www.flixon.com/2007/09/26/8/ extends the previous one by not rendering headers and footers for the empty items, though I'm not sure I like playing within Render when you can play in CreateControlHierarchy like this http://gnillydev.blogspot.com/2007/10/emptyrepeater-repeater-with-empty.html . Though I found that last one rendered the items twice**, so I combined what seemed like the best of each of them to arrive at:
protected override void CreateControlHierarchy(bool useDataSource) { // Call the base class to read the data and build up all the items base.CreateControlHierarchy(useDataSource);
// but if there are no items then use the EmptyDataTemplate instead if (this.Items.Count == 0 && EmptyDataTemplate != null) { PlaceHolder phdTemplate = new PlaceHolder(); this.EmptyDataTemplate.InstantiateIn(phdTemplate); Controls.Add(phdTemplate); } }
which seemed simpler and worked a treat - for me at least, I've not rigorously tested it.
* A mix of "Thank you for your suggestion. We will consider this addition for a future release." and "Status: Closed (Won't Fix)"
** Prob something to do with using a DataSource control to data bind
post a comment
|