views:

31

answers:

1

I did a quick search on SO for this and didn't come up with anything.

Doesn't

<%-- The following line works around an ASP.NET compiler warning --%>
<%: ""%>

seem like a bit of a hack? what's the point of this, and is the MS Dev Team doing anything to work towards a resolve?

+1  A: 

There is a writeup in the ASP.NET forums about this. Without that line, you might get compiler warnings that look something like "__o is not declared". This work around prevents those from ever appearing.

From the asp.net forums...

ASP.NET Forums

We have finally obtained reliable repro and identified the underlying issue. A trivial repro looks like this:

 <% if (true) { %>
<%=1%>
<% } %>
<%=2%>   

In order to provide intellisense in <%= %> blocks at design time, ASP.NET generates assignment to a temporary __o variable and language (VB or C#) then provide the intellisense for the variable. That is done when page compiler sees the first <%= ... %> block. But here, the block is inside the if, so after the if closes, the variable goes out of scope. We end up generating something like this:

   if (true) { 
        object @__o;
        @__o = 1;
   }
   @__o = 2;

The workaround is to add a dummy expression early in the page. E.g. <%="" %>. This will not render anything, and it will make sure that __o is declared top level in the Render method, before any potential ‘if’ (or other scoping) statement.

Tommy
thanks, that answers the first question. Any thoughts on whether or not they'll actually fix it to work properly?
rockinthesixstring
Not sure, I don't know the Visual Studio engine well enough to even pose a suggestion to get around scoping issues :/
Tommy
Of course this error has been known since at least VS 2005, so it doesn't look like there is a quick fix on the VS side of things.
Tommy