Missing IDs from ASP.NET Controls

The reason to make a control is to clump together common controls or controls plus business logic. For example, a dropdown that looks up a code and has an attached label. The HTML spec provides for dropdowns and labels, but doesn’t glue them together strongly. A Windows UI, however, will allow you to bind them strongly. .Net provides for developers to do the same things for HTML.

In ASP.NET programming, I sometimes feel very much behind the 8 ball, because I have years of client side scripting experience on web pages. So, I know exactly what I want to do. But I have no idea how Microsoft wants me to do it. I feel doubly frustrated. If I knew nothing of client script I would only wonder how Microsoft wants me to do it.

My issue revolved around the standard checkbox control in ASP.NET. The checkbox is an aggregation of a INPUT TYPE=CHECKBOX and a LABEL. Great! The problem comes in trying to control the label from client script. And when the checkbox control starts out disabled the two controls are wrapped in a SPAN tag. Neither of these sub elements of the checkbox had IDs or NAMEs. So, there is almost no way control them programmatically. This is an area where the framework looks unfinished or ameteurish. ALL elements of a control should have an ID tag so they can be controlled by client script. I really want to bang on MS here, suffice it to say I think it’s an eggregiously stupid error especially for language designers.

So what’s the solution? It can’t be possible to be unable to control the checkbox en/dis-able without refreshing the window/frame. Thank God for the DOM. If the checkbox starts out disabled it’s inside a SPAN tag which is disabled. Since one control does have an ID and is in the span tag you can get to it and ask it for it’s parent. window.all("ddnList").parent.disabled = {true, false}.

I guess if you wanted to control the label from client script you would get the checkbox ID, get the parent object, and iterate through all the label children of the parent. Ahh, so elegant. It would be such a waste of an opportunity to make beautifully circuitious code when you could to refer to an object simply by it’s unique identifier.

Leave a Reply

You must be logged in to post a comment.