开发者

ASP.NET Timer results in an updatepanel gives full postback

开发者 https://www.devze.com 2023-02-06 03:46 出处:网络
I have a quite strange situation where I have the following code: <asp:Timer ID=\"GameClock\" runat=\"server\" Interval=\"5000\" Enabled=\"true\"

I have a quite strange situation where I have the following code:

<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>

This gives a quite strange result: Every 5s my whole page gives a full postback. When I comment in (activate) the asyncpostbacktrigger, the updatepanel does not give a full postback.

In the PlayerItems_ItemDataBound I have the following code (which, I do think, do not matter):

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);


        }

    }

}

When I create a NEW updatepanel, ItemsUpdatePanel1, it does not fire a full postback without the timer. I can even start copying items from ItemsUpdatePanel to ItemsUpdatePanel1, and sudde开发者_高级运维nly the full postbacks happen. I tried 2 seperate times, and they started happening at different times!!!

Could anyone please enlighten me? I simply want the UpdatePanel NOT to give a full postback, even without a timer.

Thanks!:)


I found the solution (or, I asked on ASP.NET and found it):

http://forums.asp.net/p/1644391/4262140.aspx#4262140

The wrapping solution worked really good.


Was this project upgraded from ASP.NET 1.1? If so, check your web.config file and remove the xhtmlConformance tag from it. I forget all the specifics, but having that tag in your web.config will cause that to happen, and is there by default in .NET 1.1 web applications.

0

精彩评论

暂无评论...
验证码 换一张
取 消