Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy & Paste controls in source view of ASPX pages: How to force VS not to touch my IDs?

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.

like image 539
Slauma Avatar asked Feb 18 '10 20:02

Slauma


People also ask

What do you mean copy?

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.

Does copy mean text?

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).

What means copy in computer?

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.

What means personal copy?

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.


2 Answers

Tools > Options > Text Editor > HTML> Miscellaneous > Auto ID elements on paste in Source view. Uncheck the box to turn this feature off.

like image 99
Brian Avatar answered Sep 27 '22 16:09

Brian


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.

like image 41
Cory Grimster Avatar answered Sep 27 '22 17:09

Cory Grimster