There's one problem with any EndsWith selection - the same problem that INamingContainer is trying to solve. If the element is inside a repeater, each will end with the same value. Or, if you have two similarly named elements "Password" / "VerifyPassword" would both match for "Password". I would suggest delimiting by the separator character for some added protection.
Eric Hoff Rick: Couldn't you then use the .each() function? Also, in a situation like like a repeater it wouldn't be out of order to use a class selector. I do agree though, there are a few situations where something like "TextBox1" might happen more than once, such as multiple user controls on one page.
This is a brilliant solution John, thanks! I can't wait to try it.
John Sheehan Items in a repeater shouldn't have the same ID as that's invalid HTML (each ID should only be used once on a page) and as Eric mentioned, that's a great case for using classes. Similar named items is definitely a valid concern. The problem is if I add the underscore ASP.NET generates before the ID, pages without panels/user controls/master pages won't work with this method as they spit out a valid, unaltered ID.
I'd be fine with INamingContainer if it was limited to repeaters and such. It's master pages and user controls that cause the most problems for me.
I do agree though, there are a few situations where something like "TextBox1" might happen more than once, such as multiple user controls on one page.
This is a brilliant solution John, thanks! I can't wait to try it.