Thursday, 20 May 2010

Reliably reference a .NET control in javascript using jQuery

The clientside id of a .NET control should never be hardcoded into javascript as it's so unpredictable, and is liable to change. There is one predictable thing about it though, and that is that the rendered id will end in '_myOriginalId'.

You can take advantage of this predictability by using this syntax with jQuery, which will reliably find your control.

$("[id$='_myOriginalId']")

Tuesday, 4 May 2010

Check your server result codes / show HTTP server headers

Here's a neat little tool to check what status code your site is returning, if you don't have Firebug at hand.

It's easy to forget when you set up a bespoke 404 page that you also need to make it return the right code. If you do nothing it will return a '200 OK' status, which isn't good for SEO.

In your .NET code behind you need the following:

protected void Page_Load(object sender, EventArgs e)
        {
          Response.Status = "404 Not Found";    
        }