It’s good practice to remove identifier tags from controls that I don’t reference in Code Behind

I am wondering what feature in Visual Studio. Personally, this bothers me when I open a solution that someone else is working on and it contains controls with identifiers like "label27", "textbox3", etc.

One of the first things I do is either rename them or delete them if they are never mentioned in the code behind (as is usually the case with labels).

But I was just wondering why Visual Studio gives them such meaningless values ​​by default, then I started thinking, maybe it's better to practice something in the ID field, and not empty.

Of course, the best situation is to give them all reasonable names, but if I came across a project full of these auto-generated identifiers, can I do the author a favor by deleting them to “clear” the solution? I thought so, but not the default for dragging, copying, or pasting controls without Id?

+6
source share
2 answers

I think there is no reason to keep identifiers like that. More ids => more html => more size. I know this may not matter, but why put your source code with something that you do not want and do not need?

If you do not like the default behavior of VS, you can disable the "automatic identifier" using the settings:

Tools -> Options -> (Show All Settings) -> Text Editor -> HTML -> Miscellaneous

+7
source

VS will automatically assign an identifier to controls that you did not provide them. But if you embed some code with controls without identifiers, VS will add auto-generated names to them.

So, Microsoft thinks that all controls should have uique identifiers. And you must provide such identifiers. But if you really don’t need it, just delete the identifier to adjust the readability of your code.

The main thing is that this should be for all project controls, and it should be easy to read "clean" code.

+1
source

Source: https://habr.com/ru/post/912315/


All Articles