37

If I have the following in an ASP.NET Web Form:

<asp:TextBox runat="server" ID="tbxUser"/>

and I copy and paste that line in the same page, I usually get the following:

<asp:TextBox runat="server" ID="TextBox1"/>

Obviously, nobody is going to name their controls in that way (if you don't want to name a textbox, simply don't asign an ID to it), and it's not nice having to change the ids of pasted controls. The same happens if I copy a control without an explicit ID, VS simply generates one for me.

Is there any way of preventing VS from autogenerating IDs when I copy-paste ASP.NET code?

Alex Gyoshev
  • 11,929
  • 4
  • 44
  • 74
Diego
  • 5,024
  • 6
  • 38
  • 47
  • 2
    Great question, this really bugs me!! – digiguru Mar 04 '10 at 16:30
  • possible duplicate of [How do I prevent Visual Studio from renaming my controls?](http://stackoverflow.com/questions/484327/how-do-i-prevent-visual-studio-from-renaming-my-controls) – Andrey Aug 10 '15 at 14:08

5 Answers5

42

Options, Text Editor, HTML, Misc, Auto ID on Paste

By the way, the most similar article contains just the same question (answered, of course). Be more careful next time :)

Community
  • 1
  • 1
wRAR
  • 25,009
  • 4
  • 84
  • 97
  • 1
    weird, when I was writing the question I couldn't see that question in the similar questions list. Thanks for the link :) – Diego Mar 09 '10 at 17:08
  • 7
    FYI - regardless of what duplicates exist on stackoverflow, this one still ranked higher on Google when I searched for "visual studio disable pasting with IDs". – Chris Adams Dec 04 '12 at 05:34
3

If you're on Visual Studio 2013, see this stackoverflow question:

Disable "Auto ID elements" in Visual Studio 2013

which basically points to a bug raised with Microsoft (disabling auto id has been removed from VS 2013):

http://connect.microsoft.com/VisualStudio/feedback/details/806446/asp-net-web-forms-development-unable-to-disable-auto-id-generation-on-paste-using-new-version-of-visual-studio-2013

Community
  • 1
  • 1
Thierry_S
  • 1,526
  • 16
  • 25
3

Visual Studio 2017 doesn't seems to have a way to turn this off. If anybody knows the way, kindly post for VS 2017. Thank you.

TPG
  • 2,811
  • 1
  • 31
  • 52
2

Funny how this post is 12 years old, and at that time there was actually a solution to fix it. Fast forward to the year 2022, and a function that great has been removed by Microsoft.

The only workaround I've found online on how to do this is basically to 'fool' the IDE into thinking that "we're not pasting code."

Meaning that the best solution so far is to:

  1. Comment out the code (ctrl+k, ctrl+c)
  2. Copying that and pasting it where you'd like it to be.
  3. Uncomment the pasted code (ctrl+k, ctrl+u)

Who removes a function that works? @Microsoft

KZander
  • 300
  • 4
  • 16
0

I have a workaround ... copy part of tag . for example:

and then add the close tag ">" manually.

Best Regards'

Remawi
  • 21
  • 5