D'Arcy from Winnipeg
Solution Architecture, Business & Entrepreneurship, Microsoft, and Adoption

ASP.NET Controls - Difference between Unique and Client ID Values

Wednesday, October 24, 2007 7:44 AM

ASP.NET controls have three different ID values assigned to it:

Regular ID that's used in the designer

Unique ID that uniquely identifies it for cases where repeater-type controls are used

Client ID that uniquely identifies it on the client

The difference between the Unique and the Client ID's is this:

Unique uses the $ seperator, Client uses the _ seperator. Otherwise the values are the same.

Thanks to Shane for his post for explaining it in detail.

D




Feedback

# re: ASP.NET Controls - Difference between Unique and Client ID Values


Well thank you for that nod D'Arcy, I'm blushing hehe, honestly any time I can help...

DOH!! You said Shane Bauer!

hehe, anyway. good post. And here's something to consider with regards to Microsoft's much talked about and upcoming MVC framework. How do you extract the posted form variables in the controller?

Everything works fine right now with the postback mechanism and ViewState. You can find a submitted value by referring to the "Regular ID that's used in the designer". A text control nested inside a repeater control will have a name value of something like 'myRepeater$ctl03$myTextBox' on the client, but the postback framework in winforms today can parse this back into the proper variables and you can therefore use your reference to the repeater in the code behind and query it for the controls it contains, therfore finding your text box value.

In the upcoming MVC framework, the controller is completely separated from the code behind. Obtaining a typed reference just isn't possible anymore. So how does one know to parse something like 'myRepeater$ctl03$myTextBox' out of the submitted form variables?

I've watched guthrie's video a couple of times looking for clues and there are none to be found. He carefully skirts around how they are going to do this. In his example, he writes out native html controls into the view (ie: specifically writes the text [input type="text" name="simpleText" /], instead of using asp controls.

BUT, their claim is that aspx pages can be used as the view technology which means they will have to provide some way to parse those aspx created variable names like 'myRepeater$ctl03$myTextBox' in some meanignful way that can be used in the Controller. Right now, this is a mystery how they will do it.

One easy way might be to not write things like 'myRepeater$ctl03$myTextBox' into the rendered html in the first place and since aspx pages used in the new MCV framework will inherit from ViewPage instead of Page, I suspect this is probably what they will do. It remains to be seen!

Have I gone too deep again? Crap, I hate doing that.


Anyway, I have my own theories and am actually working on some proof of concept code. That's right, I'm going totally egghead on this one :P

We'll see what happens


10/25/2007 12:49 PM | Shaneo

Post a comment