Introduction: Anthem is a useful Ajax framework that supports ASP.NET 1.1, 2.0.
Since all controls in this framework inherit from ASP.NET's own server controls, almost all of the properties and behaviors of these controls are retained (except for changing their PostBack to CallBack's non-refresh call). So the learning curve is very gentle.
Today I encountered a troublesome debugging problem when using Anthem, which is recorded here.
In the code below, I use an Anthem.Repeater control.
<asp:XmlDataSource ID="XmlDataSource2" runat="server" XPath="//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>
Select</td>
<td>
File and drawing names</td>
<td>
Should be sent</td>
<td>
Is it original?</td>
<td>
Remarks</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">Original</asp:ListItem>
<asp:ListItem Value="False">Copy</asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:TextBox ID="txtComment" runat="server" Text='<%# XPath("Comment") %>' />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</anthem:Repeater>
</table>
When this code is run, a JS error sometimes occurs: "Unknown runtime error".
And this error only occurs in specific situations and is normal in other similar situations.
Fortunately, VS 2005 provides very powerful client-side script debugging capabilities. I finally pinpointed the error to a line of code generated by Anthem:
control.innerHTML = result.controls[controlID];
After checking the relevant information, I found that under IE, when assigning a value to the innerHTML attribute, the assigned value will be checked. If it is not well formed, an "unknown runtime error" may occur.
So I judged that there was something wrong with the HTML output by anthem.Repeater. As you can see from the two highlighted lines in the code above, the table label is outside the Repeater. Therefore, the Repeater itself outputs a series of tr, not a whole well formed.
So I put the head and tail of the table tags into the Repeater's HeaderTemplate and FooterTemplate respectively, and the problem was solved.
(The reason why I put the table tag outside before was because when I put it in the HeaderTemplate and FooterTemplate, I don’t know why the VS designer couldn’t switch to the design view. Changing it like this can solve the problem.)
After the modification is successful
,The code is as follows:
<asp:XmlDataSource ID="XmlDataSource2" runat="server" XPath="//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>
Select</td>
<td>
File and drawing names</td>
<td>
Should be sent</td>
<td>
Is it original?</td>
<td>
Remarks</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">Original</asp:ListItem>
<asp:ListItem Value="False">Copy</asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:TextBox ID="txtComment" runat="server" Text='<%# XPath("Comment") %>' />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</anthem:Repeater>
After this debugging, I feel that in addition to the benefits of fast response on the interface, Ajax also increases the difficulty of debugging due to the introduction of a large amount of js, so when applying it, you still have to make choices based on the situation. You can’t use Ajax for everything.
http://www.cnblogs.com/RChen/archive/2006/08/06/anthem_debug.html