我做了一个小实验,在页面上,放了两个Updatepanel,每个里面分别放了一个label,用来显示当前的时间。又分别用两个timer来控制上面两个updatepanel的刷新频率。一个timer1的刷新频率为1秒,另一个timer2是10秒。timer1的tick事件里,就是更新label1的时间。timer2的tick事件里,更新label1和label2的时间,并且做了一个延迟操作,这么做的意思,就是让timer2的tick操作花费一些时间。。运行问题出现了我的初衷是,两个timer各自单独刷新,不要互相影响。可是,现在,在timer2的tick事件处理时,貌似timer1的tick没有响应。。貌似这timer2在影响timer1?为什么呢?怎样才能让两个timer单独刷新???运行结果是,label2里的时间是每10秒刷新一次,正常。而label1里的时间,5秒内,正常一秒刷新一次,然后5秒内,定在那里不动如下。。
2011-6-10 10:40:18
2011-6-10 10:40:19
2011-6-10 10:40:20
2011-6-10 10:40:21
2011-6-10 10:40:22
2011-6-10 10:40:23
2011-6-10 10:40:28
2011-6-10 10:40:29
2011-6-10 10:40:30
2011-6-10 10:40:31
2011-6-10 10:40:32
2011-6-10 10:40:33
2011-6-10 10:40:38
代码如下。。前台:
<asp:ScriptManager id="scriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label ID="l1" runat="server"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Timer ID="timer1" runat="server" Interval="1000" ontick="timer1_Tick"></asp:Timer>
<asp:UpdatePanel ID="up2" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer2" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label ID="l2" runat="server"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Timer ID="timer2" runat="server" Interval="10000" ontick="timer2_Tick"></asp:Timer>
后台:
protected void Page_Load(object sender, EventArgs e)
{
scriptManager1.RegisterAsyncPostBackControl(timer2);
l1.Text = DateTime.Now.ToLocalTime().ToString();
l2.Text = DateTime.Now.ToLocalTime().ToString();
} protected void timer1_Tick(object sender, EventArgs e)
{
l1.Text = DateTime.Now.ToLocalTime().ToString();
} protected void timer2_Tick(object sender, EventArgs e)
{
l1.Text = DateTime.Now.ToLocalTime().ToString();
l2.Text = DateTime.Now.ToLocalTime().ToString();
for (int i = 0; i < 100000000; i++)
{
;
}
for (int i = 0; i < 100000000; i++)
{
;
}
for (int i = 0; i < 100000000; i++)
{
;
}
for (int i = 0; i < 100000000; i++)
{
;
}
for (int i = 0; i < 100000000; i++)
{
;
}
for (int i = 0; i < 100000000; i++)
{
;
}
for (int i = 0; i < 100000000; i++)
{
;
}
for (int i = 0; i < 100000000; i++)
{
;
}
for (int i = 0; i < 100000000; i++)
{
;
}
for (int i = 0; i < 100000000; i++)
{
;
}
}
2011-6-10 10:40:18
2011-6-10 10:40:19
2011-6-10 10:40:20
2011-6-10 10:40:21
2011-6-10 10:40:22
2011-6-10 10:40:23
2011-6-10 10:40:28
2011-6-10 10:40:29
2011-6-10 10:40:30
2011-6-10 10:40:31
2011-6-10 10:40:32
2011-6-10 10:40:33
2011-6-10 10:40:38
代码如下。。前台:
<asp:ScriptManager id="scriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label ID="l1" runat="server"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Timer ID="timer1" runat="server" Interval="1000" ontick="timer1_Tick"></asp:Timer>
<asp:UpdatePanel ID="up2" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer2" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label ID="l2" runat="server"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Timer ID="timer2" runat="server" Interval="10000" ontick="timer2_Tick"></asp:Timer>
后台:
protected void Page_Load(object sender, EventArgs e)
{
scriptManager1.RegisterAsyncPostBackControl(timer2);
l1.Text = DateTime.Now.ToLocalTime().ToString();
l2.Text = DateTime.Now.ToLocalTime().ToString();
} protected void timer1_Tick(object sender, EventArgs e)
{
l1.Text = DateTime.Now.ToLocalTime().ToString();
} protected void timer2_Tick(object sender, EventArgs e)
{
l1.Text = DateTime.Now.ToLocalTime().ToString();
l2.Text = DateTime.Now.ToLocalTime().ToString();
for (int i = 0; i < 100000000; i++)
{
;
}
for (int i = 0; i < 100000000; i++)
{
;
}
for (int i = 0; i < 100000000; i++)
{
;
}
for (int i = 0; i < 100000000; i++)
{
;
}
for (int i = 0; i < 100000000; i++)
{
;
}
for (int i = 0; i < 100000000; i++)
{
;
}
for (int i = 0; i < 100000000; i++)
{
;
}
for (int i = 0; i < 100000000; i++)
{
;
}
for (int i = 0; i < 100000000; i++)
{
;
}
for (int i = 0; i < 100000000; i++)
{
;
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货