The Evolution of Thought
While writing my Gaptcha control, I wrote a few drafts along the way of how it would work. It's funny the way things progress.
I like to think I have a pretty good knowledge of HTML, DHTML, and the HTTP protocol (which when you've got the three covered pretty much covers the whole web right? - well, most of it...) But while I know all that, that doesn't mean I'm very good at ASP.net.
Normal HTML is fine. Classic ASP I can do without a problem. ASP.net? Well, I've done my best to avoid what I can. I understand the theory, and the work I've done with it has been fine, but there's this indescribable thing in the back of my head whispering 'avoid....avoid...' that is really hard to ignore :)
But anyway, I thought it was interesting the way the work on my Gaptcha control progressed through the drafts.
In the first draft, I added some static html to the CommentForm skin file, to see how it would look.
Second, I kept most of the static html, but added a repeater control to spit out a few images. Then I added some static javascript to make the pictures clickable.
Third, I converted a lot of the static html segments to placeholder asp.net controls, and I the code behind for the blog skin engine I injected hard coded html dynamically into the placeholders at the appropriate times.
I then realised that since so much of the html was hard coded that I should use proper controls. So a few different chunks were converted to label controls.
It was at this stage that I finally decided that hard coding a selection of 9 pictures with 3 to be clicked was a bad idea, so I then converted the three labels that made up the three descriptions of the images to be clicked into a BulletedList control, so that I could as many (or few) labels as necessary, depending on the site config. It was also at this stage that I replaced the repeater control with the DataList control so that I could specify how many items wide it could repeat.
It was only then that it struck me. My chunk of stuff that was the Gaptcha control really should be a standalone control. So I converted it to a proper control and enabled it to be skinned using it's own CS skin file just like all the other controls that make up a community server blog.
So now the only thing in the CommentForm skin was the <CSB:CommentGaptcha> control, and it's code behind called that control's validate() method when a comment was submitted (in the btnSubmit's onClick event).
The control itself is now pretty good. It has some static parts (now that it is it's own control, there's no need to for the text blocks that don't change to be dynamic.
I just thought it was interesting the way it progressed. Start with what you know, then merge it into the way it should be - which, I suppose is how so many of us do everything :)