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.

UPDATE: We have to move the geek dinner to November 14th instead. There is TechEd in Barcelona the week around the 7th. 

About a month ago I attended a geek dinner in Odense that Daniel arranged and it was a great experience. Met a lot of interesting people and just had a great time. For some reason, there are no geek dinner arrangements in Copenhagen. After attending the geek dinner in Odense I realized what a shame that is. It was that good. It’s far to travel to Odense on a work night, so I definitely think a Copenhagen geek dinner is needed.

Basically what I’m saying is that I want to start a geek dinner tradition in Copenhagen and if you’re interested in participating then send me a mail or write a comment. I propose Wednesday November 7th at about 6 o’clock for the first arrangement. The plan is to meet at a restaurant to have some dinner and drinks and talk about geek stuff. No speakers or dress code, just kicking back and having fun.

If enough people show their interest, I'll find a restaurant and arrange the reservations. Stay tuned.