Live coverage for SMX Social Media


Click to Play

SMX: Helen Overland, Non-Linear...
Director of Search Engine Marketing at Non-Linear Creations, Helen M. Overland talked with WebProNews at SMX Social Media in New York City 2007. Helen...

Recent Articles

URL Rewrites & The HtmlForm Action Attribute
A known bug in ASP.NET 1.x and 2.0 is that the action attribute of a form doesn't respect URL rewrites. Everyone that uses URL rewrites uses one of several mechanisms to take care of the action attribute...

Startups Aren't Thinking About ASP.Net
Higher costs and fewer skilled .Net hackers may be limiting startups to going with the hordes of Linux and C/C++ or Java developers and tools available...

Invalid Postback Or Callback Argument
I've hooked a health provider up in my web.config to send me all unhandled exceptions by e-mail. See here how to do that - you just have to put some lines in the web.config. Well, I get all sorts of different...

Making Your ASP.NET App Extendable
People have asked me how we build the extension model into BlogEngine.NET. There's nothing to it - really, there isn't. You need one small class and 14 lines of code in the global.asax. That is all you need to...

Localizing ASP.NET (Which Is Best?)
There are different approaches to localizing an ASP.NET application. You can use a global resource file or local ones. The local resource files only applies to a single page or user control, whereas the global can be...

10.19.07


ASP.NET 2.0 - The Expando Attribute

By Mads Kristensen

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.


And this is the JavaScript it produces:


Download Now!

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.

Comments


About the Author:
Mads Kristensen currently works as a Senior Developer at Traceworks located in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in 2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and web services in his daily work as well. A true .NET developer with great passion for the simple solution.

http://www.madskristensen.dk/

About WebProASP
WebProASP is a collection of up to date tutorials and insightful articles designed to help ASP users of any skill level implement successful ASP systems and practices. ASP Strategies and Tactics for Business

WebProASP is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQlProNews.com
ITcertificationNews.com SysAdminNews.com
WebProASP.com WirelessProNews.com
CProgrammingTrends.com ITManagementNews.com




-- WebProAsp is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2007 iEntry, Inc.  All Rights Reserved  Privacy Policy  Legal

archives | advertising info | news headlines | free newsletters | comments/feedback | submit article



ASP Strategies and Tactics for Business WebProASP News Archives About Us Feedback WebProASP Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact