How to get rid of __o is not announced?

I have a code on my homepage that sets up a hyperlink with some confidential information.

<%If Not IsNothing(Profile.ClientID) Then%> <span class="menu-nav"> <a target="_blank" href= "http://b/x.aspx?ClientID=<%=Profile.ClientID.ToString()%>&Initials=<%=Session("Initials")%>" > Send <br /> SMS <br /> </a> </span> <%End If %> <span class="menu-nav"> <!-- Name __o is not declared Error is flagged here--> 

Now the problem seems to be in the href part. If I delete the dynamic code, the error will disappear. Can someone tell me how to solve this problem?

+48
Apr 15 '09 at 9:19
source share
5 answers

I found the answer on .net forums. It contains a good explanation of why ASP.Net acts as it is:

Finally, we got reliable reprogramming and identified the main problem. The trivial review is as follows:

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

To provide intellisense in <% =%> blocks during development, ASP.NET generates assignment of a temporary variable __o and language (VB or C #), then provides intellisense for the variable. This is done when the page compiler sees the first block <% = ...%>. But here the block is inside the if, so after closing the if this variable goes out of scope. As a result, we get something like this:

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

The workaround is to add a dummy expression on the early page. For example. <% = ""%>. This will do nothing, and it will make sure that __o is declared the top level in the Render method before any potential if statement (or other scoping).

An alternative solution is simple use.

 <% response.write(var) %> 

instead

 <%= var %> 
+66
Apr 15 '09 at 10:11
source share
โ€” -

Yes, I occasionally encountered the same error on pages that use server-side constructs on ASPX pages.

Overtime, I found a fix for it (sorry, I just couldnโ€™t find out where I found this bit of information again), and this fix is โ€‹โ€‹to put the following code above errant <%...%> block:

 <%-- For other devs: Do not remove below line. --%> <%="" %> <%-- For other devs: Do not remove above line. --%> 

Apparently where you put the above code, everything matters for VS.NET, so it may take a few attempts to get it right.

+14
Apr 15 '09 at 9:24
source share

This is a strange solution, but for me I was able to fix this problem by simply closing open files with violation in Visual Studio.

With their discovery, I mistakenly got the __o problem.

As soon as I closed them, the __o problem disappeared.

+2
May 20 '14 at 13:28
source share

After hours of searching on Google and analyzing the heap of aspx'ses in my current project, it looks like I have found a solution that works for me. I would not advise strongly avoiding html-style comments:

<!-- ... -->

inside an aspx page. Use aspx style comments instead

<%-- ... --%>

In addition, it helped me to get vs intellisense and code highlighting to work again, and mainly - this case started with it - now you can hit breakpoints inside the built-in parts of vb / cs code! And no damn message "This is the wrong location for the breakpoint."

0
Nov 15 2018-11-11T00:
source share

When I cleared the solution, restarted IIS, and it still mysteriously plays out, I believe that sometimes this can be caused by pasting the contents of the ASPX source file from another system into Visual Studio, which โ€œhelpsโ€ update the code, some identifiers may change, and violation pages.

Paste it into another editor (Notepad ++?), And then save it so that Visual Studio does not "help" and the page works again.

0
Nov 23 '17 at 10:14
source share



All Articles