简体   繁体   中英

How to Add REGION in Visual Studio in aspx Files

I use asp.net with code behind and c#.

So I have two file for every .aspx page in VS 2010.

In .aspx.cs page I am able to add regions in my code using:

#region Name Region
#endregion

My questions:

  • How to do it in file .aspx? #region seems working only in .cs file.
  • Do you know any other useful tag to help me to organize better my code both for .aspx and .cs file?
  • Do you know the keyboard shortcuts to expand or collapse all my region in my code?

Thanks for your help.

Do you know the keyboard shortcuts to expand or collapse all my region in my code?

Here are some key chords for you.

Ctrl-M Ctrl-O will collapse all the regions in the opened document (or the highlighted section).

Ctrl-M Ctrl-M will collapse or open the collapsible section the cursor is on.

Ctrl-M Ctrl-L will collapse or open everything.

Now here is one i use frequently, especially in javascript files: highlight some code, then press Ctrl-M Ctrl-H to hide it, which will produce a little expander +- next to the collapsed code. Press Ctrl-M Ctrl-O to expand it again.

Also see this blog post by Scott Guthrie which details some posters you can download with lots of the VS shortcut key combinations on them.

The editor of Visual studio for aspx files already provide features like collapsing and expanding for individual elements of HTML.

You can hit '-' at the left most corner in the editor to collapse the corresponding HTML tag (Div or table, etc.) and sub contents.

You can try putting it inside a some other container. For example
<asp:Literal id="JavaScriptRegion" runat="server">
.... I put all my javascripts here.
</asp:Literal>

So I can collapse the Javasript "region". If it's inside your body section and you have asp ctrols inside you might try something like
<div style="">....

It should be mentioned that if you use the hotkeys:

  • CTRL + M , CTRL + O
  • CTRL + M , CTRL + M
  • CTRL + M , CTRL + L
  • CTRL + M , CTRL + T

etc., they wont be saved when you save and reopen your project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM