更新面板无法正常工作

时间:2013-08-28 07:49:56

标签: asp.net updatepanel

我在更新面板中放置了一个数据绑定控件。并设置一个计时器,每隔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();
}

已编辑的身体

1 个答案:

答案 0 :(得分:1)

我通过从更新面板中删除计时器并将其放在更新面板之外来解决此问题

相关问题