开发者

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

开发者 https://www.devze.com 2022-12-20 19:36 出处:网络
If I drag a control from the toolbox in Visual Studio (2008+SP1) into an ASPX page I get a proposal for an ID:

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="But开发者_如何学Goton" />

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消