Thursday, May 13, 2010

VS editor displays "__o is not declared" error

This generally happens when you use render blocks in your aspx pages. Basically in order to provide intellisense at design time, VS assigns the value inside the block to a temporary variable "__o". It defines the variable whereever it first encounters the render block. so let say if your very first render block is inside if block then the variable "__o" scope would be within that block only and any other render block statement outside the if block will show design time error.
to reproduce this issue, copy and paste following lines of code in your aspx

<% If True Then %>



<%=2 %>

End If%>

Although the VS editor does not show this error consistently but if you don't want to touch your existing code and get rid of this annoying error(though does not affect your actual compilation) then just place a blank render block above all so that the "__o" variable scope goes page level and the variable would be accessible everywhere.

Now paste the following code and compare it with above code, you will find that just by adding a blank render block fixed the issue

<%="" >
<% If True Then >



<%=2 >

End If>