How to collapse javascript functions using <% = in Visual Studio 2012

In Visual Studio 2012, when editing / aspx markup, you can apparently collapse javascript functions if they do not contain special server tags, such as a shortcut for Response.Write <% = .

<strong> Examples:

May crash:

 function foo() { var x = 0; } 

May not collapse:

 function bar() { var x = $find("<%= txtWhatever.ClientID %>"); } 

I noticed, as soon as you add the opening tag <% = , the collapse ( - ) option is to the left of the word function disappears, so I know the problem.

It seems to break the whole function, regardless of size / content.

I tried the Web Essentials plugin and Advanced Javascript highlights the plugin , but none of them work for functions with this specific content.

Is there a way to reset functions containing these types of tags?

Thanks -

+6
source share
2 answers

Only workaround:

Wrap each function in your script tag.

About this, an error was probably discovered with the JS team.

+4
source

I use the "Three Script" template:

Script 1


Page Level Variables.


Script 2


'Getter / Setter', which return links to server controls or get / set values.

For instance:

 function GetTxtUserNameVal() { var rtn = $('#<%= txtUsername.ClientID %>').val(); return rtn; } function SetTxtUserNameVal(arg) { $('#<%= txtUsername.ClientID %>').val(arg); } function GetUserDetailsGrid() { return $find('<%= gridUserDetails.ClientID %>'); } 


Script 3


Functions:

In them, I use the getter / setter functions above, not the server tags.



Now I can collapse the scripts, and can also individually collapse all the functions in the script functions.

0
source

All Articles