If I drag a control from the toolbox in Visual Studio (2008+SP1) into an ASPX page I get a proposal for an ID:
<asp:Button ID="Button1" runat="server" Text="Button" />
That's nice and helps not to forget to assign an ID. Most of the time I rename the ID like:
<asp:Button ID="MySpecialButtonForSpecialTask1" runat="server" Text="Button" />
Now I have a task 2 (3, 4, ..., n) and need a button "MySpecialButtonForSpecialTask2". So I copy and paste the first one with ID="MySpecialButtonForSpecialTask1". That's the result:
<asp:Button ID="Button1" runat="server" Text="Button" />
That's not nice since I need to change now "Button1" to "MySpecialButtonForSpecialTask2" but I would prefer to change "MySpecialButtonForSpecialTask1" to "MySpecialButtonForSpecialTask2".
Is there any setting or trick in VS to prevent assigning new IDs after copy and paste?
Update
I'm not looking for the option
"Tools > Options > Text Editor > HTML> Miscellaneous > Auto ID elements on paste in Source view"
since it also turns off creating IDs for controls inserted from the toolbox. I only would like to switch off this when copy & paste.
1 : an imitation, transcript, or reproduction of an original work (such as a letter, a painting, a table, or a dress) 2 : one of a series of especially mechanical reproductions of an original impression also : an individual example of such a reproduction.
Broadly defined, copy is text within a publication or composition. It is in contrast to any graphic or pictorial aspects of a publication, article, or another kind of composition. Those in publishing often refer to the main text of an article as body copy (as opposed to titles, subheads, or other elements).
The Copy command creates a duplicate of a piece of data in a storage area in Windows called clipboard. The Paste command inserts the data from the clipboard in the place where you use this command. The clipboard can hold different data like text, images, videos, files or folders.
Personal copying occurs when individuals make, or allow copies to be made, of copyrighted materials for their own use and enjoyment; they may or many not own a licensed copy of the work.
Tools > Options > Text Editor > HTML> Miscellaneous > Auto ID elements on paste in Source view. Uncheck the box to turn this feature off.
Sometimes when I need to copy a block of aspx code and just change the name of the controls I use Notepad as an intermediary.
For example:
<asp:Label ID="lblFoo" runat="server" Text="Enter Foo:" />
<asp:TextBox ID="txtFoo" runat="server" />
If I wanted to copy these controls and change "Foo" to "Bar", I would copy the above into Notepad, Ctrl-H to replace "Foo" with "Bar", then paste the results into Visual Studio.
This tends to be quite handy when dealing with a large number of controls.
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