By coincidence I noticed a method I’ve never seen before on the ClientScript property of the page class in ASP.NET 2.0. It’s called something as cryptic as RegisterExpandoAttribute and it’s very useful.

It can set JavaScript properties on any element you would normally reference with document.getElementById(‘elementID’). That means you can control the state of your HTML elements from the code-behind in a very easy manor. It also means you can control HTML elements that don’t have a runat=”server” attribute.

Here are two examples – one where a property is set on a server-control and one on a HTML element otherwise invisible to the code-behind.

Page.ClientScript.RegisterExpandoAttribute(txtPassword.ClientID, "value", "britney");

Page.ClientScript.RegisterExpandoAttribute("maintable", "background", "red"); 

And this is the JavaScript it produces:

<script type="text/javascript">
<!--
var txtPassword = document.all ? document.all["txtPassword"] : document.getElementById("txtPassword");
txtPassword.value = "britney";
// -->
</script>

I think where this really rocks the most is the ability to control regular HTML elements that hasn’t got the runat=”server” attribute. Those elements have always been invisible to the code-behind and now you have direct server-side access to their properties. The method doesn't give you anything you couldn't do before, but it makes it so much easier and cleaner.

The last couple of months I’ve been pretty focused on accessibility and have found that links in the header can help. You know the link tag in the header from the way you embed stylesheets and RSS auto-discovery links. They can do a lot more than that.

The links can tell about the relations that exist between the current page and the rest of the website. Different browsers such as Mozilla and Opera can then display the links as part of the website’s navigation in a common way. Also screen readers can use this approach to ease the navigation and there are plug-ins for both Firefox and IE.

In the image you can see that this site supports Home, Content, Search, Previous, Next and Author as a navigational aid and that there are even more link types it doesn’t support. To support the Home link type, just write this in the <head> element of your web page:

<link rel="start" title=".NET slave" href="/" />

The Contents type looks like this:

<link rel="contents" title="Archive" href="/archive.aspx" />

For more information about the various link types for the <head> element, then see here and here. You can also see a list of browsers that supports header links. This is also a feature in the upcoming version of BlogEngine.NET due in a few weeks.