Before proceeding to the implementation details, let’s discuss a little about how ASP.NET handles automatic Id generation.
First of all, the Control.UniqueID property is the key to all major ASP.NET benefits. In fact, ASP.NET gives us unique Id’s for each control which give us a deterministic way of recreating page controls. Without this, Viewstate and Events were impossible to achieve.
ASP.NET also gives us the concept of naming controls, that enable us to easily find the correct control and to write more perceptible code, but [more]it is also here that Microsoft engineers made the mistake:
“They decided to use the given name in the unique Id generation.”
This is why we can find ‘id’ and ‘name’ attributes as long as I’ve shown you earlier.
My naming concept is similar to our real live naming conventions:
“Although we all have a different Identity Card Id it’s possible to exist several citizens with the same name.“
This way, the control will have a:
- machine to machine identity (Control.UniqueID )
- human to machine identity (Control.ID)
This is not a new concept, attend in the ‘id’ and ‘name’ html attributes roles:
- id attribute is there to allow us to find the correct elements (human to machine identity)
- name attribute isn’t used by programmer but its value is the one posted to server (machine to machine identity)
So, we understand that, in order to reduce the unique Id length, it’s mandatory to decouple the Control.UniqueID and the Control.ID properties.
Once decoupled, Control.UniqueID will keep its main goal, and even the generation algorithm will stay unchanged.
Our big challenge is to effectively decouple the two properties without changing the ASP.NET paradigm, this mean that changes made should be transparent to programmer.
An important note to keep in mind is that this approach assumes that ‘id’ and ‘name’ attributes wont be human perceptible, and that the only way to uniquely identify a html element that maps a Server control is to use the Control.ClientID property to compose script statements.
I will soon post the implementation details.