有個空間

          有個標題

          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編程技巧


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


          網站導航:
           
          主站蜘蛛池模板: 临颍县| 阜康市| 宜川县| 兴宁市| 银川市| 建宁县| 康保县| 兰溪市| 庐江县| 蒲江县| 革吉县| 陕西省| 台北县| 临夏县| 正安县| 东安县| 博兴县| SHOW| 疏附县| 江北区| 靖江市| 高邑县| 株洲县| 旌德县| 望谟县| 滕州市| 手机| 昌乐县| 礼泉县| 朔州市| 合江县| 哈密市| 庆安县| 大埔县| 呼图壁县| 乌拉特前旗| 博乐市| 板桥市| 安泽县| 哈尔滨市| 大悟县|