22

Region code collapse for JS in Visual Studio 2012 and 2013 ?

#region AutoComplete JS
$("#<%=txtBirim.ClientID %>").autocomplete({
   source: function (request, response) {
     $.ajax({
       url: '<%=ResolveUrl("~/Classlar/TextboxOtomatik.asmx/BirimGetir") %>',
       data: "{ 'prefix': '" + request.term + "'}",
       dataType: "json",
       type: "POST",
       contentType: "application/json; charset=utf-8",
       success: function (data) {
       response($.map(data.d, function (item) {
         return {
         label: item.split('-')[0],
         val: item.split('-')[1]
       }
      }))
     },
    Code....
#endregion

Is there anyway to do something like this ?

Hakan Fıstık
  • 11,376
  • 8
  • 74
  • 105
TheMuyu
  • 522
  • 2
  • 9
  • 25

5 Answers5

39

Install web essentials

Use the same name in end region

//#region AutoComplete JS
$("#<%=txtBirim.ClientID %>").autocomplete({
      source: function(request, response) {
          $.ajax({
                url: '<%=ResolveUrl("~/Classlar/TextboxOtomatik.asmx/BirimGetir") %>',
                data: "{ 'prefix': '" + request.term + "'}",
                dataType: "json",
                type: "POST",
                contentType: "application/json; charset=utf-8",
                success: function(data) {
                  response($.map(data.d, function(item) {
                    return {
                      label: item.split('-')[0],
                      val: item.split('-')[1]
                    }
                  }))
                },
                Code....
//#endregion AutoComplete JS
Pandiyan Cool
  • 5,804
  • 5
  • 45
  • 80
  • 3
    you need to count with WebEssentials... http://vswebessentials.com/features/javascript – Silvestre Jul 14 '15 at 03:11
  • @QMaster install WebEssentials – Pandiyan Cool Dec 31 '18 at 04:18
  • although @umair solution working I will check to see WebEssentials was installed or not and If not I must decide about is it wise to install that just for using js region! – QMaster Dec 31 '18 at 09:14
  • Installed WebEssentials but unfortunately not working in some section of JS code, e.g. $(document).on("click", "..... – QMaster Dec 31 '18 at 10:36
  • The @umair solution is not persistent, unfortunately :( – QMaster Dec 31 '18 at 10:40
  • I found all of the solutions have issues with Razor @ symbol in javascript if you have any. So I searched and this link must be useful: https://stackoverflow.com/a/8794065/1830909 – QMaster Dec 31 '18 at 13:16
8

It worked for me after installing the Visual Studio Advanced Javascript Outlining extension.

You can find the extension here

After installing the extension just restart your Visual Studio and you can use it like this

//#region MyRegion

Code Here

//#endregion 
Hakan Fıstık
  • 11,376
  • 8
  • 74
  • 105
prem
  • 2,442
  • 1
  • 18
  • 45
  • Solution posted is for VS version 2012/13 as asked by the OP. – prem Jun 14 '17 at 09:09
  • The Advanced Javascript Outlining extension is not working with VS 2017 up to this moment. Is there some other way to get the region collapse for VS 2017? – Thomas.Benz Sep 04 '17 at 14:04
  • 1
    For 2017- Download Extension from here https://marketplace.visualstudio.com/items?itemName=MadsKristensen.JavaScriptRegions – Charlie Jun 14 '18 at 09:31
5
  1. select the javascript code you want to hide 2.Press (

a.Ctrl+M

then

b.Ctrl+H ) then you can can name you region

Umair Ghouri
  • 61
  • 1
  • 1
  • more details on this page http://blog.degree.no/2013/05/define-a-region-in-javascript-files-visual-studio-2010-2012/ – desiguy Dec 14 '16 at 16:01
  • I upvoted this answer but I find after closing project outlines [ created with ctrl+M -> ctrl+H ] was removed :( – QMaster Dec 31 '18 at 10:38
3

if you use Web Essentials in Visual Studio than you can write

//#region AutoComplete JS
youcode
//#endregion

see this link

1

Visual Studio: Just select the code area you want to collapse then right click on the mouse, click on Outlining then click on Hide Selection. You will get the collapse (+) sign on the left vertical bar. The Shortcut Key is Ctrl+M then Ctrl+H after selection.

Jahid
  • 21
  • 3