首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

多个UpdatePanel,只定时刷新其中一个,如何做?

2012-04-20 
多个UpdatePanel,只定时刷新其中一个,怎么做?急!急!前台代码:div styleheight: 143px width: 545px

多个UpdatePanel,只定时刷新其中一个,怎么做?急!急!

前台代码:

  <div style="height: 143px; width: 545px">
  <asp:ScriptManager ID="ScriptManager1" runat="server">
  </asp:ScriptManager>
  <asp:UpdatePanel ID="UpdatePanel1" runat="server">
  <ContentTemplate>
  <asp:Label ID="Label1" runat="server"></asp:Label>
  </ContentTemplate>
  <Triggers>
  <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
  </Triggers>
  </asp:UpdatePanel>
  <asp:UpdatePanel ID="UpdatePanel2" runat="server">
  <ContentTemplate>
  <asp:Label ID="Label2" runat="server"></asp:Label><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  </ContentTemplate>
  <Triggers>
  <asp:AsyncPostBackTrigger ControlID="Timer2" EventName="Tick" />
  </Triggers>
  </asp:UpdatePanel>
  <asp:Timer ID="Timer1" runat="server" Interval="3000" OnTick="Timer1_Tick">
  </asp:Timer>
  <asp:Timer ID="Timer2" runat="server" Interval="5000000" OnTick="Timer2_Tick">
  </asp:Timer></div>


后台代码:

 protected void Page_Load(object sender, EventArgs e)
  {
  if(!IsPostBack)
  {
  GetDate();
  }
  }

  private void GetDate()
  {
   
   
  }

  protected void Timer1_Tick(object sender, EventArgs e) 
{
 Label1.Text = "UpdatePanel1 更新于: " + DateTime.Now.ToLongTimeString();
 }
  protected void Timer2_Tick(object sender, EventArgs e)
 { 
Label2.Text = "UpdatePanel2 更新于: " + DateTime.Now.ToLongTimeString();
 } 

想要UpdatePanel 定时更新,UpdatePanel2 输入时不被刷新
请指教!!!请指教!!!
请指教!!!
请指教!!!



[解决办法]
试试这个

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DemoCSDN.aspx.cs" Inherits="DemoCSDN" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:Timer ID="Timer1" runat="server" Interval="1">
</asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<%=DateTime.Now.ToString() %>
</ContentTemplate>
<Triggers>


<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class DemoCSDN : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Timer1_Tick(object sender, EventArgs e)
{
int tickcount = 0;
if (ViewState["TickCount"] != null)
{
tickcount = (int)ViewState["TickCount"];
}
tickcount++;
ViewState["TickCount"] = tickcount;
if (tickcount > 10)
{
Timer1.Enabled = false;
}

}
}

热点排行