Tuesday, February 24, 2004

Off To Israel

Well, after a very thorough security check at the ElAl check in at Heathrow, I'm on my way to Tel Aviv for two weeks, working with Panam.

If anyone needs to get in contact with me I'll be checking my email on a regular basis, and I'm staying at the Seasons Hotel in Netanya.

It's going to be the longest time that Bec and I have been apart since, well, forever. I just hope that Zak and India don't play her up too much while I'm away (but then again, what else can I expect from a fiesty almost 3 year old, and a very demanding 11 month old). Of course, Bec being 7 and a half months pregnant makes things even more interesting for her.

Damn I'm going to miss them all.

Oh well, off to the duty free shops...

 Monday, February 23, 2004

ASP.NET Focus Component

One of the small irritants in the ASP.NET framework is there is no built-in mechanism to set the focus of a control directly in code - you have to emit javascript to handle the job for you.

This is no problem, as ASP.NET gives you standard methods that allow you to register client script blocks with a page, but most of the solutions I've seen to this problem so far involve adding code directly to the inherited Page object to do the job.

However, this to me is untidy and as it's a common enough function to want to achieve, it would be nice to have a component you can quickly drop onto your page.

The code that follows does exactly that; once added to your toolbox, you can drop this component onto your ASP.NET design surface. From the properties box, simply set the ControlToFocus property to the control you want to, er, focus.

It works by handling the target controls' PreRender event, and injecting a startup script into the associated Page object. Very, very simple.

using System;
using System.ComponentModel;
using System.Web.UI;

namespace EdCourtenay.Community.WebControls
{
    public class FocusSetter : Component
    {
        private Control focusControl = null;
    
        public FocusSetter()
        {}

        public Control ControlToFocus
        {
            get { return focusControl; }
            set
            {
                if (focusControl != null)
                    focusControl.PreRender -= new EventHandler(FocusControlPreRender);

                focusControl = value;

                if (focusControl != null)
                    focusControl.PreRender += new EventHandler(FocusControlPreRender);
            }
        }

        private void FocusControlPreRender(object sender, EventArgs e)
        {
            Control control = (Control)sender;
            Page page = control.Page;

            if (page != null)
            {
                string script = String.Format("<script type=\"text/javascript\">document.getElementById(\"{0}\").focus();</script>", control.UniqueID);
                page.RegisterStartupScript("focusControl", script);
            }
        }
    }
}

 Saturday, February 21, 2004

The format of the file 'VSUserControlHost.dll' is invalid

I've been struggling for a few days with an exception that kept on being raised when authoring my own composite ASP.NET Web Controls:

The format of the file 'VSUserControlHost.dll' is invalid

After spending some time banging my head against a brick wall, it turns out that the cause was the otherwise excellent CodeSmith plugin for VS.NET, which I use to produce things like type-safe collections; disabling it removes the problem immediately.

 Thursday, February 12, 2004

Gallery Online

I've installed a copy of nGallery 1.5 over at http://gallery.edcourtenay.co.uk where I'll be keeping pictures of my kids and other stuff.

nGallery itself is really very cool, and best of all it's free.

 Thursday, February 05, 2004

Silence is Golden

DRM madness strikes over at Apple iTunes. Buying DRM crippled tracks is bad enough, but DRM crippled encoded silence?