I'm wondering about a feature in Visual Studio. Personally it bugs me when I open a solution someone else has been working on and it's full of Controls with Ids like "label27" "textbox3" etc.
One of the first things I do is either rename them or remove them if they are never referenced in code behind (as is usually the case with the labels).
But I was just wondering why Visual Studio defaults them such meaningless values, then I started thinking if maybe it is better practise to have something in the Id field rather than blank it.
Of course the best situation is to give them all sensible names, but if I come across a project full of those auto generated Ids, am I doing the author a favour by removing them to "clean up" the solution? I used to think so, but wouldn't the default for dragging and dropping or copying and pasting controls in be without an Id?
I think there's no reason to keep IDs like that. More ids => more html => more size. I know, this may be not significant, but why to plague your source code with something you don't want and don't really need?
If you don't like VS's default behavior, you can disable "auto id-ing" via settings:
Tools -> Options -> (Show all settings) -> Text editor -> HTML -> Miscellaneous
VS will assign ID automatically to the controls you haven't provide them to. But if you are pasting some code with controls without IDs, VS will add autogenerated names to them.
So, Microsoft thinks that all the controls should have uique IDs. And you should provide such IDs. But if you really don't need them, so simply remove ID to adjust readability to your code.
The main point is this should be for all controls accross the project, and it should be easy to read "clean" code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With