Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it good practise to remove Id tags from Controls that I don't reference in Code Behind

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?

like image 363
Mikey Mouse Avatar asked Apr 03 '12 12:04

Mikey Mouse


2 Answers

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

like image 146
walther Avatar answered Sep 30 '22 15:09

walther


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.

like image 29
VMAtm Avatar answered Sep 30 '22 15:09

VMAtm