有個空間

          有個標題

          vb asp.net error <__o is not declared>

          FWD: http://stackoverflow.com/questions/750902/how-do-i-get-rid-of-o-is-not-declared

          I've found the answer on the .net forums. It contains a good explanation of why ASP.Net is acting the way it is:

          [quote]

          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.

          [/quote]

          An alternative solution is to simply use

          <% response.write(var) %>

          instead of

          <%= var %>
          link|edit|

          posted on 2011-03-16 16:16 游雯 閱讀(133) 評論(0)  編輯  收藏 所屬分類: .net編程技巧


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 湄潭县| 札达县| 庄河市| 德江县| 东阿县| 额尔古纳市| 定南县| 巧家县| 枞阳县| 田东县| 潮州市| 仲巴县| 贞丰县| 申扎县| 应城市| 孝感市| 平顶山市| 东源县| 云浮市| 扎兰屯市| 乌拉特前旗| 同江市| 同仁县| 云安县| 武乡县| 年辖:市辖区| 八宿县| 凤城市| 北碚区| 木里| 当涂县| 施甸县| 左云县| 陆河县| 丹寨县| 娄烦县| 澜沧| 辛集市| 商都县| 徐汇区| 青州市|