views:

396

answers:

2

Are there any options (third-party or otherwise) to improve code folding within the Source Editor for HTML/ASP.Net?

The #region directive makes it easier to create your own sections, but it doesn't work in the Source Editor. Ideally I'd like to fold away larger areas of code than between the server-side code blocks. But below shows what happens...

<% // Search Results Section            <-- Just want folding here

   foreach (int item in list) { %>  <-- but it is here also
       Number : <% =item %>
   <% }        

   //etc...
%>

Code folding falls between <% and %> which isn't really where I want it. I'm trying to get sections of code.

A: 

I'm not sure exactly what you are after here. You can do something like this:

//some code
#region "my foreach loop"
foreach(int item in list)
{
//so dome work
}
#endregion
//some more code

and if your requirement is that the name of the region after you colapse it is the loop definition, you can just copy it like so

//some code
#region "foreach(int item in list)"
foreach(int item in list)
{
//so dome work
}
#endregion
//some more code

Now if you are looking for code folding in the .aspx page, I think you are pretty much restricted to within the tags. It's kind of a red flag if you have logic in your page that is so complex that it needs folder, though. You might consider moving it to the code behind and folding it as necessary there.

Drithyin
I agree that too much code in a section is a red-flag, unfortunately I'm kinda stuck with what I've got -- :)
Hugoware
+2  A: 

I'm guessing by your example you are looking for some sort of ASP.Net Markup code folding solution. VS 2008 Pro (unsure as to your version) will allow you to "Collapse Tags" via context menu (right-click) on a server tag or highlighted section of mark up.

Tyler
That works for me - Thank you!
Hugoware