Refector-Rename ASP.Net Controls - visual-studio

Is there any way to Rename ASP.Net Controls without searching the complete Markup or Codebehind.
In Visual Studio there is Refactor Rename but this only works in Codebehind I still have to search the Markup code.
I'm using VS 2008.

Yes. I've found that the easiest way to do this is from the code behind.
There exists a shortcut called Rename Refactoring that is bound to the keyboard combination (Ctrl+R, Ctrl+R). The combination is listed as "Refactor.Rename" in the keyboard settings, if you want to change the shortcut (or if it's not bound, for some reason, you can set it yourself.)
To rename your ASP.NET control, navigate in the aspx.vb file to a reference of the control. Put your mouse cursor on the variable name. Press the keyboard shortcut. Now, you can either start typing (will erase the previous name and start typing a new name), or click somewhere or use the arrow keys to navigate to a specific position in the variable, after which you can add/remove/change the name as you please.
Clicking elsewhere will not apply the changes. To apply the operation, either click "Apply" in the dialog at the top-right that appeared, or press Enter.
The ASP control will be renamed in the VB code, and in the aspx code!
Note that there are certain file types where Refactor.Rename is "not available", such as .ashx or Visual C++ files.

Related

Visual Studio : How can I remap the Ctrl+E key?

I am using Visual Studio 2013, and I would like Ctrl+E to map to Edit.LineEnd. Basically, the same thing that happens when you hit end.
I can remap it under options/environment/keyboard, but the problem is visual studio still treats Ctrl+E as a chord. Instead of going to the end of the line when I hit Ctrl+E I see a message below :
(Ctrl+E) was pressed. Waiting for second key of chord.
This does not happen when I remap Ctrl+A, Ctrl+N, Ctrl+P, Ctrl+F, or Ctrl+B.
This looks like a side effect of how Visual Studio layers command routing and key bindings...
If you look at the default bindings (my settings were based on the C# profile), you can see there are a ton of other bindings that start with Ctrl+E:
Important observations:
Each command has its context specified in parenthesis (Global, Text Editor, Workflow Designer)
There is already a multi-key (chord?) binding in the Text Editor
The Workflow Designer bindings don't matter/conflict because they're in a completely separate context
If you set your binding in the Global scope, it falls last on the priority (i.e. any specific context overrides a more generic one). Since you're in the text editor, it's trying to match the chord that exists in that context.
If you were to bind your new shortcut in the Text Editor (that's the dropdown labeled Use new shortcut in:, which defaults to Global), it would actually remove the keybinding for Edit.ToggleWordWrap. That's because you can't have a keybinding overlap with a chord, so VS assumes you really want the one you're trying to add and nukes the conflicts.
Alternatively, if you want to keep both, you could remap Edit.ToggleWordWrap to a different binding first.

visual studio, which bookmark is this

I am debugging my code and come across a bookmark I set earlier, my bookmarks have nice names, and I would like to know which bookmark this it. The bookmark window is open, and the last bookmark I clicked on is highlighted, but not the one I am on.
How do I ask visualstudio, “What is the name of the bookmark, that is on this line of code?”
My current method is to click each bookmark in turn, in the bookmark window until I get back to the line I was looking at.
(using visual studio 2012, professional)
There is no command to synchronize Bookmarks window with current cursor position but you can use this macro as a workaround. The macro assumes that the bookmark where the cursor is is enabled and it will enable all bookmarks after run, which may be a problem to your use case.
Sub SyncBookmarksWindow()
DTE.ExecuteCommand ("Edit.EnableAllBookmarks")
DTE.ExecuteCommand ("Edit.EnableBookmark")
DTE.ExecuteCommand ("Edit.NextBookmark")
DTE.ExecuteCommand ("Edit.EnableAllBookmarks")
End Sub
Bind this macro to a keyboard shortcut and sync away.
EDIT: Unfortunately VS2012 does not allow for macros anymore, and you have to create an Add-In. For how-to see another question on this site.

Expression Blend reload file shortcut

Is there any way to reload a file open in expression blend, from using a keyboard shortcut or any other shortcut? Currently, while in expression blend, I just close it from the "x" button, and then re-open it, but its tedious. Is there any other alternative?
I find myself needing to close a file and re-open it to refresh the design view. Because if I edit for example some data templates, the changes I made in the code part of the split view, are not reflected immediately in the design part of the split view.
Hence, I need a way to make blend reload the file.
EDIT: One way to overcome this limitation is to make the content inside your data-template a user control and edit that in Blend.
But my initial question still stands.

Single layout for 'edit' and 'debug' in Visual Studio

In Visual Studio 2008, 'Start Debugging' switches Visual Studio to a different layout. How can I force Visual Studio to use a single layout at all times?
I could attempt to lay out my windows in both normal and 'Debug' modes as similarly as possible. However, i) Visual Studio will still do a visible redraw, and ii) I have to keep the layouts in sync manually.
Update: It seems the correct terms are 'Design View' and 'Debugging View'. According to Window Layouts: The Four Modes 'There is no way to tell Visual Studio to use one state for all modes at this time.' Is this really true?
As others have pointed out, you can't use one settings group to control both design and debug views. Visual Studio doesn't make it easy to get the most out of window placement settings, but the approach I use to manage layouts might help.
Instead of frequently adjusting window placements by hand, try to think of a fixed number of different views you want to work with. Eclipse has perspectives, window layouts you can switch between. Think of Visual Studio this way. For example, I use two layouts in Visual Studio: one to take advantage of two monitors when I'm sitting at my physical workstation, another for one monitor when I'm working remotely. If you can constrain yourself to using a group of layouts that makes sense for you without manually adjusting windows, you can make design and debug window placements the same for each layout.
However, switching between layouts is painful with Visual Studio out of the box. You have to go to Tools->Import and Export Settings and select the layout manually. It takes more than five mouse clicks and sometimes 15 seconds to switch layouts this way on my workstation. We can do much better!
Save the window positions you want for each layout to settings files
Make a macro to load each settings file
Bind the macros to keyboard shortcuts or toolbar buttons
Save window positions to a settings file
Arrange windows the way you want them for a specific layout. Visual Studio saves the location for nearly every window (e.g. Solution Explorer, Output, Find and Replace), so be thorough. Visual Studio saves design and debug layouts in a single file so arrange windows in both views.
Go to Tools->Import and Export Settings. Choose Export selected environment settings and click Next.
The next dialog prompts you to select the settings to export. Uncheck all settings except General Settings/Window Layouts so only window placements are saved, like in these screen shots (I can't expand the window so here are two shots of the same dialog):
Enter a name for this settings file and save it. Repeat until you have a settings file for each layout. There is no limit to how many settings files you may have.
Make a macro to load each settings file
Go to Tools->Macros->Macro Explorer to show your macros. There should already be a macro project named MyMacros. Create an empty macro project if none are visible. Double click any module in any of these projects to open up the macro editor.
Enter this into the editor. You want one main sub that takes a path to a settings file and loads the file, and one sub for each individual file that calls the main sub. If you save your settings files to the same folder you can have the per-file subs pass just the file name instead of the whole path.
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module Module1
Private RootFolder As String = "C:\Path\To\Folder\With\Settings\Files\"
Private Sub ImportSettingsFile(ByVal FileName As String)
FileName = IO.Path.Combine(RootFolder, FileName & ".vssettings")
DTE.ExecuteCommand("Tools.ImportandExportSettings", "-import:""" & FileName & """")
End Sub
'Corresponds to file layoutA.settings
Public Sub ImportLayoutA()
ImportSettingsFile("layoutA")
End Sub
'Corresponds to file layoutB.settings
Public Sub ImportLayoutB()
ImportSettingsFile("layoutB")
End Sub
'Repeat for each settings file
End Module
Close the macro editor and go back to Visual Studio. You're done! Running any of these macros will load the settings files automatically. You can double click any of the subs in Macro Explorer to run them. If you display Macro Explorer at all times this might be sufficient, but if you don't or would rather not have to click the macros to run them we can do even better ...
Bind the macros to keyboard shortcuts or toolbar buttons
Go to Tools->Options->Environment->Keyboard. This window allows you to change any keyboard bindings. Type "Macro" without quotes into the Show commands containing text box. This will show the macros you created. Select any macro, click in the text box titled Press shortcut keys, and enter the keyboard shortcut you want to use to run the macro. Hit Assign, then OK. You can now use this keyboard command to load the settings file.
Alternately, you can use a toolbar button instead of or in addition to a keyboard binding. Go to Tools->Customize. Select the Commands tab, select Toolbar, and select the toolbar you want to add the button to (Standard is the main toolbar). Click Add Command, select the Macros category, select the macro you want to add a button for, and click OK. You will have a new button on the toolbar that loads the window layout from that macro.
Keep in mind that keyboard shortcuts and toolbar buttons are themselves settings. If you import a settings file that overwrites either of them you will have to redo this last step. The window placement settings files won't overwrite these values because you only exported window locations. It's a good idea to periodically export and back up all settings, not just window settings, in case something like this happens and you want to recover non-window settings.
No, this is not possible. The website you found is indeed accurate:
There are four different window layout modes in Visual Studio:
Design View - this is the one you see when you start up Visual Studio. It's what most people refer to as the "normal" view.
Debugging View - this is the view that you get when you enter Debug Mode like when you are stepping through your code
Full Screen - the view you get when you go to View -> Full Screen (Shift + Alt + Enter).
File View - the lesser known view you can get when you open up a file in DevEnv.eve
The thing to remember here is that, both, your tool windows and your command bar customizations are saved separately for each state. There is no way to tell Visual Studio to use one state for all modes at this time. Additionally, when you shut down Visual Studio in any state, all four states are saved.
It's very strange that you would want to use the same window layout for all four modes. The same windows that are useful at design time are hardly ever useful during debugging, and vice versa.
For example, in Debugging View, I hide the Toolbox, Document Outline, and Property Manager windows. Then, I add the immensely useful Call Stack, Autos, Locals, Processes, Modules, and Breakpoints windows. None of the latter panes would be remotely useful to me in design mode, so I don't want them taking up screen space. But they're invaluable in debug mode, so I want them to show up. I also resize windows in the two different modes, based on their relative importance (such as the Properties window).
If you really still think that the two views should have the same window layout, the best you can do is rearrange the windows manually to achieve the same layout in both modes. I also recommend exporting your Window Layout settings (Tools -> Import and Export Settings) so that you have a fresh copy to revert back to in the case of disaster. I keep settings files containing my preferred window layout settings for single monitor (laptop), dual monitor, and triple monitor configurations.
I think your question was, "How do I use the same settings for both modes?" Am I right? Although #Chris gave an excellent thesis on how to stuff automagically, I wanted to point out, for anyone else that finds this question that there is an easy way to acheive same window settings for both design and debug modes.
Export your settings:
Choose General Settings/Window Layouts (in VS 2013) and save the file.
Open the file in an XML editor (or whatever... it's an XML file)
Find /UserSettings/Category/Design/WindowProfile and copy the entire node.
-- This assumes your Design view is the one you want to use for both modes.
Find /UserSettings/Category/Debug/WindowProfile and replace it with the one you copied from Design.
Save and re-import.
I have one of these settings files for home, remote, and office.
Many people try to turn off this feature because of strange behaviors (glitches) of VS windows on multi-monitor configurations.
In such cases there is another option that can help:
Turn off Environment->General->"Optimize rendering for screens with different pixels densities"
https://developercommunity.visualstudio.com/content/problem/830128/windows-layout-not-restoring-properly-in-multi-mon.html

How do I view Visual Studio BuildLog.htm files without cutting and pasting into an external browser

This may or may not be specific to VS2005 (as that is the version I'm referring to for this question).
I find often the case is that I see this in the Output panel inside Visual Studio
2>Build log was saved at "file://c:\\vsdll_example\MyExecRefsDll\Debug\BuildLog.htm"
Now, since that looks and smells like a URL, I would have thought that I could simply left mouse click on it, or left mouse double-click on it, and a browser window of some sort would be displayed. No, that doesn't work. So, to view it, I have to cut and paste the "file://bla/bla/bla" part into an external window.
Is there a way to set up Visual Studio to allow me to browse to that file directly, or view it inside Visual Studio IDE, or something to that effect, without the extra fiddling with cutting and pasting? Or is there some type of keybinding I'm not aware of?
Thanks,
bg
Hold down Control while clicking on the link. It should show up in the editor.

Resources