2

我在更新面板中放置了一个数据绑定控件。并设置一个计时器,每 5 秒刷新一次。但它没有更新更新面板内的 div。为了更新数据,我必须刷新整个页面。我在 master page.myhtml 代码中使用它

 <asp:ScriptManager ID="ScriptManager1" runat="server">
 </asp:ScriptManager>
 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:Timer ID="Timer1" runat="server" Interval="5000" ontick="Timer1_Tick">
        </asp:Timer>
        <br />
        <div style="height:480px;overflow:scroll;">
        <asp:Repeater ID="Repeater1" runat="server">
       <ItemTemplate>

                   <div id="message" >
                   <img id="image" alt="visitors" runat="server" src="~/icon-visitors.png" height="32" width="32" /></td><td>
                      <b>A New visitor come from </b><b class="data"><%#Eval("lt_country") %>
</ItemTemplate>
            </asp:Repeater>
           <button id="btn1" style="visibility:visible;">yiui</button>
           </div>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
        </Triggers>
    </asp:UpdatePanel>

而c#代码是

 protected void Page_Load(object sender, EventArgs e)
{
   // Page.ClientScript.RegisterStartupScript(this.GetType(), "http://localhost:49415/WebSite5/panel_advertiser/adver_files/js/JScript.js", "alert('hello world!');");
    add();
    Rep_Bind();
}
private void Rep_Bind()
{   
      objprop.Query = "select lt_country,lt_browser,lt_ip,pk_id from log_unique where lt_username='myfunline' order by pk_id desc limit 3";
      MySqlDataAdapter adp = new MySqlDataAdapter(objprop.Query, ConfigurationManager.AppSettings["constring"].ToString());
      DataSet ds = new DataSet();
      adp.Fill(ds);
      Repeater1.DataSource = ds;
      Repeater1.DataBind();
}
protected void Timer1_Tick(object sender, EventArgs e)
{

   // ClientScript.RegisterClientScriptBlock(this.GetType(), "blah", "http://localhost:49415/WebSite5/panel_advertiser/adver_files/js/JScript.js", false);
    Rep_Bind();
}

编辑正文

4

1 回答 1

1

I solve this by removing timer from update panel,and placing it outside the update panel

于 2013-09-04T04:29:47.223 回答