I have some code in my master page that sets up a a hyperlink with some context sensitive 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 issue seems to be in the href part. If I remove the dynamic code the error disappears. Can anyone tell me how to resolve this issue?
现在问题似乎在href部分。如果我删除动态代码,错误就消失了。谁能告诉我怎么解决这个问题吗?
5 个解决方案
#1
66
I've found the answer on the .net forums. It contains a good explanation of why ASP.Net is acting the way it is:
我在。net论坛上找到了答案。它很好地解释了为什么使用ASP。Net的行为方式是:
We have finally obtained reliable repro and identified the underlying issue. A trivial repro looks like this:
我们最终获得了可靠的结果,并发现了潜在的问题。一个普通的repro看起来是这样的:
<% 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:
为了在设计时在<%= %>块中提供智能感知,ASP。NET生成对临时__o变量和语言(VB或c#)的赋值,然后为变量提供智能感知。当页面编译器看到第一个<%=…% >块。但是这里,块在if中,所以在if关闭之后,变量就会超出范围。我们最终生成这样的东西:
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.
解决方法是在页面的早期添加一个假表达式。例如< % = " " % >。这将不会呈现任何内容,并且它将确保__o在呈现方法的顶层声明,在任何潜在的“if”(或其他范围)语句之前。
An alternative solution is to simply use
另一种解决方案是简单地使用。
<% response.write(var) %>
instead of
而不是
<%= var %>
#2
14
Yes, I have experienced the same bug occasionally in pages that use server side constructs on ASPX pages.
是的,我偶尔在使用ASPX页面上的服务器端构造的页面中遇到过相同的错误。
Overtime, I found a fix for it (I'm sorry, I just haven't been able to find out where I found this bit of info again.) and that fix is to put the following code above the 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 makes all the difference to VS.NET, so it may take a few tries to get it right.
显然,上面代码的位置对VS.NET有很大的影响,所以可能需要几次尝试才能把它写对。
#3
2
This is an odd solution, but for me I managed to fix this problem by simply closing the offending open files in Visual Studio.
这是一个奇怪的解决方案,但是对我来说,我通过简单地关闭Visual Studio中不正常的打开文件来解决这个问题。
With them open, i was erratically getting the __o problem.
由于它们是打开的,所以我得到了错误的__o问题。
As soon as I closed them, the __o problem disappeared.
我一闭上他们,问题就消失了。
#4
0
After some hours of googling and analyzing bunch of aspx'ses in my current project seems I've found the solution, that is working for me. Would to advise strongly avoid html-style comments:
在我目前的项目中搜索和分析了几个小时之后,我似乎找到了适合我的解决方案。强烈建议尽量避免html格式的评论:
<!-- ... -->
< !——……- - >
inside aspx page. Instead of it use aspx-style comments
在aspx页面。而不是使用aspx风格的注释
<%-- ... --%>
< %——…——% >
Additionally it helped me obtain that vs intellisense and code highlighting became working again and the mainly thing - this case had begun from it - vs can now hit the breakpoints inside embedded pieces of vb/cs code! And no any damn "This is not a valid location for a breakpoint" message.
此外,它还帮助我获得了vs intellisense和代码高亮显示重新开始工作,主要的事情——这个案例已经开始了——vs现在可以在vb/cs代码的嵌入片段中找到断点了!没有任何该死的“这不是断点的有效位置”消息。
#5
0
When I've cleaned the solution, restarted IIS and it is still mysteriously playing up, I find this can sometimes be caused by pasting an ASPX source file's contents from another system into Visual Studio which "helpfully" updates the code, possibly changing some IDs and breaking the page.
当我清理了解决方案、重新启动IIS并且它仍然神秘地运行时,我发现这有时可能是由于将一个ASPX源文件的内容从另一个系统粘贴到Visual Studio中而导致的,该Visual Studio“帮助”更新代码,可能会更改一些id并破坏页面。
Pasting it into another editor (Notepad++?) then saving it stops Visual Studio from "being helpful" and the page works again.
将它粘贴到另一个编辑器(Notepad+ ?)中,然后保存它,使Visual Studio不再“有用”,页面再次工作。
#1
66
I've found the answer on the .net forums. It contains a good explanation of why ASP.Net is acting the way it is:
我在。net论坛上找到了答案。它很好地解释了为什么使用ASP。Net的行为方式是:
We have finally obtained reliable repro and identified the underlying issue. A trivial repro looks like this:
我们最终获得了可靠的结果,并发现了潜在的问题。一个普通的repro看起来是这样的:
<% 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:
为了在设计时在<%= %>块中提供智能感知,ASP。NET生成对临时__o变量和语言(VB或c#)的赋值,然后为变量提供智能感知。当页面编译器看到第一个<%=…% >块。但是这里,块在if中,所以在if关闭之后,变量就会超出范围。我们最终生成这样的东西:
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.
解决方法是在页面的早期添加一个假表达式。例如< % = " " % >。这将不会呈现任何内容,并且它将确保__o在呈现方法的顶层声明,在任何潜在的“if”(或其他范围)语句之前。
An alternative solution is to simply use
另一种解决方案是简单地使用。
<% response.write(var) %>
instead of
而不是
<%= var %>
#2
14
Yes, I have experienced the same bug occasionally in pages that use server side constructs on ASPX pages.
是的,我偶尔在使用ASPX页面上的服务器端构造的页面中遇到过相同的错误。
Overtime, I found a fix for it (I'm sorry, I just haven't been able to find out where I found this bit of info again.) and that fix is to put the following code above the 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 makes all the difference to VS.NET, so it may take a few tries to get it right.
显然,上面代码的位置对VS.NET有很大的影响,所以可能需要几次尝试才能把它写对。
#3
2
This is an odd solution, but for me I managed to fix this problem by simply closing the offending open files in Visual Studio.
这是一个奇怪的解决方案,但是对我来说,我通过简单地关闭Visual Studio中不正常的打开文件来解决这个问题。
With them open, i was erratically getting the __o problem.
由于它们是打开的,所以我得到了错误的__o问题。
As soon as I closed them, the __o problem disappeared.
我一闭上他们,问题就消失了。
#4
0
After some hours of googling and analyzing bunch of aspx'ses in my current project seems I've found the solution, that is working for me. Would to advise strongly avoid html-style comments:
在我目前的项目中搜索和分析了几个小时之后,我似乎找到了适合我的解决方案。强烈建议尽量避免html格式的评论:
<!-- ... -->
< !——……- - >
inside aspx page. Instead of it use aspx-style comments
在aspx页面。而不是使用aspx风格的注释
<%-- ... --%>
< %——…——% >
Additionally it helped me obtain that vs intellisense and code highlighting became working again and the mainly thing - this case had begun from it - vs can now hit the breakpoints inside embedded pieces of vb/cs code! And no any damn "This is not a valid location for a breakpoint" message.
此外,它还帮助我获得了vs intellisense和代码高亮显示重新开始工作,主要的事情——这个案例已经开始了——vs现在可以在vb/cs代码的嵌入片段中找到断点了!没有任何该死的“这不是断点的有效位置”消息。
#5
0
When I've cleaned the solution, restarted IIS and it is still mysteriously playing up, I find this can sometimes be caused by pasting an ASPX source file's contents from another system into Visual Studio which "helpfully" updates the code, possibly changing some IDs and breaking the page.
当我清理了解决方案、重新启动IIS并且它仍然神秘地运行时,我发现这有时可能是由于将一个ASPX源文件的内容从另一个系统粘贴到Visual Studio中而导致的,该Visual Studio“帮助”更新代码,可能会更改一些id并破坏页面。
Pasting it into another editor (Notepad++?) then saving it stops Visual Studio from "being helpful" and the page works again.
将它粘贴到另一个编辑器(Notepad+ ?)中,然后保存它,使Visual Studio不再“有用”,页面再次工作。