日期:2014-05-17  浏览次数:20497 次

UpdatePanel 刷新问题
C# code
protected void Timer1_Tick(object sender, EventArgs e)
    {
        DataSet ds = AccessDAL.Books.Books_Tanchu(0, 0);
        if (ds.Tables[0].Rows.Count > 0)
        {
            Literal1.Text = "<div style=\"height:300px;\">";
        }
        else
        {
            Literal1.Text = "<div style=\"height:300px;display:none;\">";
        }
    }

C# code

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Timer1_Tick(Timer1, new EventArgs());
        }
    }



HTML code

        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
        <asp:Timer ID="Timer1" runat="server" Interval="5000" ontick="Timer1_Tick"></asp:Timer>
        
                <asp:Literal ID="Literal1" runat="server"></asp:Literal>
                <div id="msg_win" style="top:503px;overflow: hidden;">
                <div class="icos"><a id="msg_min" title="最小化" href="javascript:void 0">_</a><a id="msg_close" title="关闭" href="javascript:void 0">×</a></div>
                    <div id="msg_title">通知:</div>
                    <div id="msg_content">您好,当前您有信息未读。<a href="Books/books_list.aspx?page=31" target="mainFrame">点击进入</a></div>
                </div></div>
            </ContentTemplate>
                        <Triggers>
                            <asp:AsyncPostBackTrigger    ControlID="Timer1" />
                        </Triggers>
        </asp:UpdatePanel>


为什么一直刷新 
但是我做了一个后台更新新闻前台自动更新的就不刷新 也是这套代码
大虾们帮看看

------解决方案--------------------
幫你UP下吧

每次回調都可調試的,看有沒有回調不就清楚了,又或是回調處出現異常導致沒刷新,不過你上面是正常的,呵呵
------解决方案--------------------
[code=HTML][/code]<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Timer Example Page</title>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
OriginalTime.Text = DateTime.Now.ToLongTimeString();
}

protected void Timer1_Tick(object sender, EventArgs e)
{
StockPrice.Text = GetStockPrice();
TimeOfPrice.Text = DateTime.Now.ToLongTimeString();
}

private string GetStockPrice()
{
double randomStockPrice = 50 + new Random().NextDouble();
return randomStockPrice.ToString("C");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="Sc