国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET技巧:使用 Anthem.NET 框架的一個調試經歷

2024-07-10 13:09:59
字體:
來源:轉載
供稿:網友

  簡介:anthem 是一個很好用的 ajax 框架,支持 asp.net 1.1, 2.0。

  由于該框架的所有控件都繼承自 asp.net 自身的服務器控件,保留了幾乎所有這些控件的屬性和行為(除了把它們的 postback 改為 callback 的無刷新調用之外)。所以學習曲線很平緩。

  今天我在使用 anthem 的時候碰到了一個比較麻煩的調試問題,記錄于此。

  在下面的代碼中,我用了一個 anthem.repeater 控件。

        <asp:xmldatasource id="xmldatasource2" runat="server" xpath="http://needdocs/doc"
        enablecaching="false"></asp:xmldatasource>
        <table class="mytable" width="100%" cellspacing="0" cellpadding="0">
          <anthem:repeater id="rptneeddocs" runat="server" datasourceid="xmldatasource2"
          autoupdateaftercallback="false">
            <headertemplate>
              <tr class="formtitle">
                <td>
                  選中</td>
                <td>
                  文件、圖紙名稱</td>
                <td>
                  應送</td>
                <td>
                  是否原件</td>
                <td>
                  備注</td>
              </tr>
            </headertemplate>
            <itemtemplate>
              <tr>
                <td>
                  <asp:checkbox id="chkdoc" runat="server" checked="true" />
            <asp:hiddenfield id="hiddocid" runat="server" value='<%# xpath("@id") %>' />
                </td>
                <td>
              <asp:label id="lbldocname" runat="server" text='<%# xpath("@name") %>' />
                </td>
                <td>
                  <asp:textbox id="txtquantity" runat="server" text='<%# xpath("@quantity") %>' width="30" />
                </td>
                <td>
                  <asp:radiobuttonlist id="radiolist_isoriginal" runat="server" selectedvalue='<%# xpath("@isoriginal") %>'
                    repeatdirection="horizontal">
                    <asp:listitem value="true">原件</asp:listitem>
                    <asp:listitem value="false">副本</asp:listitem>
                  </asp:radiobuttonlist>
                </td>
                <td>
                  <asp:textbox id="txtcomment" runat="server" text='<%# xpath("comment") %>' />
                </td>
              </tr>
            </itemtemplate>
            <footertemplate>
            </footertemplate>
          </anthem:repeater>
        </table>

  這個代碼在運行時,有時候會出現一個 js 錯誤:“未知的運行時錯誤”。

  而該錯誤只在特定情況下發生,在其他類似情況下正常。

  幸虧 vs 2005 提供了非常強大的客戶端腳本調試功能。我終于將錯誤定位到了 anthem 產生的一行代碼上:

control.innerhtml = result.controls[controlid];

  查了相關資料后發現,在 ie 下,對 innerhtml 屬性賦值的時候,會對所賦的值進行檢查。如果不是 well formed, 則可能會出現“未知的運行時錯誤”。

  于是我判斷 anthem.repeater 輸出的 html 出了問題。從上面代碼中高亮的兩行可以看到,table 標簽在 repeater 的外面。因此 repeater 本身輸出的是一系列 tr, 并不是 well formed 的一個整體。

  于是我將 table 的標簽頭尾分別放入 repeater 的 headertemplate 和 footertemplate,問題解決。

 (之所以先前把 table 標簽放到外面去了,是因為放在 headertemplate 和 footertemplate 中的時候,不知道為什么 vs 的設計器不能切換到設計視圖了。而改成這樣可以解決問題。)

  修改成功后的代碼如下:

        <asp:xmldatasource id="xmldatasource2" runat="server" xpath="http://needdocs/doc"
        enablecaching="false"></asp:xmldatasource>
        <anthem:repeater id="rptneeddocs" runat="server" datasourceid="xmldatasource2" autoupdateaftercallback="false">
          <headertemplate>
            <table class="mytable" width="100%" cellspacing="0" cellpadding="0">
              <tr class="formtitle">
                <td>
                  選中</td>
                <td>
                  文件、圖紙名稱</td>
                <td>
                  應送</td>
                <td>
                  是否原件</td>
                <td>
                  備注</td>
              </tr>
          </headertemplate>
          <itemtemplate>
            <tr>
              <td>
                <asp:checkbox id="chkdoc" runat="server" checked="true" />
                <asp:hiddenfield id="hiddocid" runat="server" value='<%# xpath("@id") %>' />
              </td>
              <td>
                <asp:label id="lbldocname" runat="server" text='<%# xpath("@name") %>' />
              </td>
              <td>
                <asp:textbox id="txtquantity" runat="server" text='<%# xpath("@quantity") %>' width="30" />
              </td>
              <td>
                <asp:radiobuttonlist id="radiolist_isoriginal" runat="server" selectedvalue='<%# xpath("@isoriginal") %>'
                  repeatdirection="horizontal">
                  <asp:listitem value="true">原件</asp:listitem>
                  <asp:listitem value="false">副本</asp:listitem>
                </asp:radiobuttonlist>
              </td>
              <td>
                <asp:textbox id="txtcomment" runat="server" text='<%# xpath("comment") %>' />
              </td>
            </tr>
          </itemtemplate>
          <footertemplate>
            </table>
          </footertemplate>
        </anthem:repeater>

  經過這次的調試,我覺得 ajax 除了帶來了界面上響應迅速的好處之外,因為引入大量 js,也增大了調試的難度,因此應用的時候還是要根據情況取舍。不能什么都上 ajax.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 娱乐| 邵武市| 张家界市| 襄垣县| 托里县| 乌鲁木齐市| 广灵县| 个旧市| 长岛县| 郴州市| 姚安县| 沧源| 达孜县| 余庆县| 灵台县| 当涂县| 北宁市| 洪泽县| 湛江市| 和顺县| 姚安县| 南平市| 莎车县| 沂源县| 哈密市| 扎鲁特旗| 道真| 松滋市| 新沂市| 武平县| 德清县| 资兴市| 廉江市| 枞阳县| 寿阳县| 江北区| 木兰县| 临邑县| 武胜县| 通辽市| 加查县|