我有一个非常奇怪的情况,我有以下代码:
<asp:Timer ID="GameClock" runat="server" Interval="5000" Enabled="true"
ontick="GameClock_Tick">
</asp:Timer>
<asp:UpdatePanel ID="ItemsUpdatePanel" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<Triggers>
NOTE THE TRIGGER IS COMMENTED OUT
<%--<asp:AsyncPostBackTrigger ControlID="GameClock" EventName="Tick" />--%>
</Triggers>
<ContentTemplate>
<asp:ListView ID="PlayerItems" runat="server" GroupItemCount="7"
onitemdatabound="PlayerItems_ItemDataBound">
<LayoutTemplate>
<table border="1" cellpadding="2" cellspacing="0" runat="server" id="tblProducts">
<tr runat="server" id="groupPlaceholder">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<td id="Td1" runat="server" style="vertical-align:top; text-align:left; height:100%;">
<div>
<div id="category" runat="server">
<asp:Panel ID="ItemPanel" runat="server">
</asp:Panel>
</div>
</div>
</td>
</ItemTemplate>
<GroupTemplate>
<tr runat="server" id="productRow">
<td runat="server" id="itemPlaceholder"></td>
</tr>
</GroupTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
这给出了一个非常奇怪的结果:我的整个页面每5秒发出一次完整的回发。当我评论(激活)asyncpostbacktrigger时,updatepanel不会提供完整的回发。
在PlayerItems_ItemDataBound中,我有以下代码(我认为,这无关紧要):
protected void PlayerItems_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
ListViewDataItem dataItem = e.Item as ListViewDataItem;
if (dataItem != null)
{
BaseItem myItem = dataItem.DataItem as BaseItem;
Panel itemPanel = new Panel();
Literal firstLiteral = new Literal();
firstLiteral.Text += "<div id='smoothmenu1' class='ddsmoothmenu'>";
firstLiteral.Text += "<ul>";
firstLiteral.Text += "<li><img src='Images/Game/Items/" + myItem.ItemImageUrl + "' />";
firstLiteral.Text += "<ul>";
// Add all events bound to item into contextmenu
itemPanel.Controls.Add(firstLiteral);
foreach (Delegate del in myItem.Actions.Items)
{
Literal firstItLit = new Literal();
firstItLit.Text += "<li>";
itemPanel.Controls.Add(firstItLit);
MethodInfo methodInfo = del.Method;
string commandName = myItem.ItemId + "|" + methodInfo.Name;
LinkButton btn = new LinkButton();
btn.Text = methodInfo.Name;
btn.Click += new EventHandler(btn_Click);
btn.CommandName = commandName;
itemPanel.Controls.Add(btn);
Literal secondItLit = new Literal();
secondItLit.Text += "</li>";
itemPanel.Controls.Add(secondItLit);
}
Literal btnLiteral = new Literal();
btnLiteral.Text += "</ul>";
btnLiteral.Text += "</li>";
btnLiteral.Text += "</ul>";
btnLiteral.Text += "</div>";
itemPanel.Controls.Add(btnLiteral);
Panel panel = (Panel)(e.Item.FindControl("ItemPanel"));
panel.Controls.Add(itemPanel);
}
}
}
当我创建一个新的更新面板ItemsUpdatePanel1时,它不会在没有计时器的情况下触发完整的回发。 我甚至可以开始将ItemsUpdatePanel中的项目复制到ItemsUpdatePanel1,突然发生完整的回发。我尝试了两次,他们开始时间不同!
有谁可以请赐教?我只是希望UpdatePanel不提供完整的回发,即使没有计时器。
感谢:!)
答案 0 :(得分:2)
答案 1 :(得分:0)
此项目是否已从ASP.NET 1.1升级?如果是这样,请检查您的web.config文件并从中删除xhtmlConformance
标记。我忘记了所有细节,但在web.config中使用该标记会导致这种情况发生,并且在.NET 1.1 Web应用程序中默认存在。