日期:2014-05-18  浏览次数:20535 次

实时刷新的问题
要求用的是ms的ajax ,设置timer的Interval=“9000”,然后执行如下方法(页面要无刷新):
  aspx: 放置lable1

cs:
C# code

  
private void test()
{
    lable1.Text="<script> alert('"+DateTime.Now.ToString()+"');</script>";
}

//必须是执行test()这方法得到,效果是每9s弹出一次当前时间.请教大虾。最佳者100分送上,谢谢




------解决方案--------------------
lable1.Text="<script> alert('"+DateTime.Now.ToString()+"');</script>";
不明白为什么要这样写?
如果你要label显示时间,这样写
private void test()
{
Label1.Text = DateTime.Now.ToString();
}

protected void Timer1_Tick(object sender, EventArgs e)
{
test();
}
如果要alert,必须这样写
private void test()
{
ScriptManager.RegisterStartupScript(UpdatePanel1, GetType(), "time", "alert('" + DateTime.Now.ToString() + "');", true);
}

protected void Timer1_Tick(object sender, EventArgs e)
{
test();
}

前台这样写
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="9000" OnTick="Timer1_Tick" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
测试通过.
------解决方案--------------------
关注,UP
------解决方案--------------------
可以在前台用js来刷新的
------解决方案--------------------
ScriptManager.RegisterStartupScript(UpdatePanel1, GetType(), "time", "bll返回的Js代码",true); 

------解决方案--------------------
ScriptManager.RegisterStartupScript(UpdatePanel1, GetType(), "time", "bll返回的Js代码",true); 
用这个就挺不错的
------解决方案--------------------
用这个ScriptManager.RegisterStartupScript(UpdatePanel1, GetType(), "time", "alert('" + DateTime.Now.ToString() + "');", 不错
但是为什么还要Label1放在UpdatePanel1上面,本来就是要弹出框,label1可以不要了吧