code-u-like

C#, .Net, Sql Server, Salesforce, Dynamics CRM etc,
Charity and Not-for-Profit sector

Thursday, March 27, 2008

Server Controls, UniqueID and Master pages

Recently I was updating some ASP.NET pages for a client. They had a set of custom-built server controls that worked very happily, binding data to and from domain objects. I modified some of the ASP.NET pages so that they became Content pages that shared a common Master page. Then suddenly all the Server controls stopped working - they were not processing postbacks properly or firing events. That is, Server Controls that had worked in normal ASP.NET pages suddenly stopped working in Master-Content pages.

Eventually I tracked the problem down to the overridden Render method in the Server Controls, and the id that was rendered to HTML. If you Render your Server Controls like this:

protected override void Render(HtmlTextWriter output)
{
// . . .
output.AddAttribute("id", this.ID);
output.AddAttribute("name", this.ID);
output.RenderBeginTag("input");
output.RenderEndTag();
// . . .
}

... and the control also implements IPostBackDataHandler (with the LoadPostData method and so on), the control will work as long as it is not inside a composite control or a control container.

However, if you put the control inside a control container (such as a ContentPlaceHolder in a Master-Content page), ASP.NET will no longer be able to figure out how to map the Form data that gets posted to the server back to the control. Hence LoadPostData (and RaisePostDataChangedEvent) will not get called.

This bug is easily fixed - the html ID and Name of your control should be rendered using UniqueID, as follows:

protected override void Render(HtmlTextWriter output)
{
// . . .
output.AddAttribute("id", this.UniqueID);
output.AddAttribute("name", this.UniqueID);
output.RenderBeginTag("input");
output.RenderEndTag();
// . . .
}

(In fact, "id" might not be needed at all, but is useful. "name" is the one that maps Form data on postback)

Of course, most documentation stresses that Server Controls should render using UniqueID if they want to catch postback data (Here's the MSDN documentation on Capturing Postback Events in Server Controls). But this might catch people out, because if you use ID instead of UniqueID, your control might happily work for years until you put it into a control container.

See also: MSDN - Developing Custom Controls: Key Concepts

Labels:

Monday, March 17, 2008

Neverending Spam War

Saw this in the footer of an email I received:
" ... Please check your Junk folder regularly for any correspondence we might send."
lol

Monday, March 10, 2008

Bug Hunter in Space

In 1987, Acorn launched the Archimedes home computer. At the time, it was the fastest desktop computer in the world, and at the time, I was fortunate enough to have one to experiment with.

The Archimedes was great, but it never really took off commercially. However, it was built around the ARM processor, which Acorn had designed itself when it could not find any existing processors suitable for its 32-bit ambitions. The ARM processor was a masterpiece of simple and intuitive design, and its still around today, with most of the instruction set pretty much unchanged. In fact, you've probably got one in your pocket right now. Its design makes it process very efficiently on low energy intake, and hence it is estimated that about 98% of all mobile phones contain an ARM chip. Over 10 billion ARM chips have been shipped, and they outnumber Intel's long running x86 series of chips by a factor of about 5 to 10.

I had learned programming on the BBC Model B, and when we got the Archimedes it was a massive upgrade and I spent a lot of time devising computer games. At first these were in BBC Basic V, an interpreted language, but even with a fast processor, optimisation is very important in games, so I obtained a compiler for BBC Basic and also started learning some ARM Assembler to speed up the graphics routines. Although the Archimedes had built-in sprite routines for plotting bitmaps to the screen, bitmap plotting with ARM Assembler was much faster because you could write bitmap data straight into the video memory area with just a handful of instuction cycles.

I spent quite a lot of time sending demo floppy disks to the companies that published games for the Archimedes at that time (Clares Micro, Superior Software, Minerva) and after many rejection letters, Minerva software agreed to publish a game of mine, 'Bug Hunter' in May 1990. The sequel, 'Bug Hunter In Space', followed soon after that, in November of the same year.



There weren't that many Archimedes users around to actually buy the game, but it was still great to have something published. I still have the reviews that appeared in Acorn User and other magazines in a scrapbook. And developing games was great fun, a mixture of coding (everything had to be fast), graphic design (everything had to look nice) and psychology (the puzzles had to have the right level of difficulty). Writing the games also gave me some real world experience of the end-to-end development of a project, at around the same time that I sat my GCSEs.

The Archimedes is long gone now (production ceased in 1992) but there is still a 'Risc-OS Community' (named after the Archimedes OS) in existence on the internet, with emulators such as Virtual Acorn and Acorn clone machines such as the Iyonix PC and the A9Home.

Bug Hunter in Space is one of those games people seem to remember, so it still gets mentioned here and there. A lot of old games have become freeware now, so a couple of years ago I got back in touch with the people from Minerva who had originally published the game, and they were happy to let Bug Hunter in Space go freeware (as long as it is distributed intact with the original attributions etc).

So if you happen to have an Archimedes/RISC-OS emulator, you can download the games for free here:

Bug Hunter In Space (Original 'adf' Disc Image)
Bug Hunter In Space (Extracted and modified for later Risc-OS versions)
Bug Hunter (Original 'adf' Disc Image)
Bug Hunter (Extracted and modified for later Risc-OS versions)

Also, in the unlikely event that you want the original boxed version, RetroGames currently have a copy on sale for £35 : )

Labels: