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;\">";
        }
    }protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Timer1_Tick(Timer1, new EventArgs());
        }
    }        <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>为什么一直刷新 
但是我做了一个后台更新新闻前台自动更新的就不刷新  也是这套代码
大虾们帮看看

解决方案 »

  1.   

    <%@ 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="ScriptManager1" runat="server" />
            <asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="10000" />        <asp:UpdatePanel ID="StockPricePanel" runat="server" UpdateMode="Conditional">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer1" />
            </Triggers>
            <ContentTemplate>
                Stock price is <asp:Label id="StockPrice" runat="server"></asp:Label><BR />
                as of <asp:Label id="TimeOfPrice" runat="server"></asp:Label>  
            </ContentTemplate>
            </asp:UpdatePanel>
            <div>
            Page originally created at <asp:Label ID="OriginalTime" runat="server"></asp:Label>
            </div>
        </form>
    </body>
    </html>