<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="1000"
ontick="Timer1_Tick">
</asp:Timer>
<asp:Label ID="lblMess" runat="server" Text=""></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
后台这样:
protected void Timer1_Tick(object sender, EventArgs e)
{
//从数据库中读取的时间 int time =5;//假如数据库存储的是5秒 this.lblMess.Text = (time--).ToString();
if(time==0)
(
//执行操作
)
}
请问,这样怎么不行,该怎么写,时间才走??
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="1000"
ontick="Timer1_Tick">
</asp:Timer>
<asp:Label ID="lblMess" runat="server" Text=""></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
后台这样:
protected void Timer1_Tick(object sender, EventArgs e)
{
//从数据库中读取的时间 int time =5;//假如数据库存储的是5秒 this.lblMess.Text = (time--).ToString();
if(time==0)
(
//执行操作
)
}
请问,这样怎么不行,该怎么写,时间才走??
protected void Timer1_Tick(object sender, EventArgs e)
{
//从数据库中读取的时间 this.lblMess.Text = (time--).ToString();
if (time == 0)
{
//执行操作
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
//从数据库中读取的时间
int time = 5;//假如数据库存储的是5秒
if (Session["time"] != null)
time = (int)Session["time"];
this.lblMess.Text = (time--).ToString();
Session["time"] = time;
if (time == 0)
{
//执行操作
}
}
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick">
</asp:Timer>
<asp:Label ID="lblMess" runat="server" Text=""></asp:Label>
</ContentTemplate>
</asp:UpdatePanel> public int time ;
protected void Page_Load(object sender, EventArgs e)
{
time = 5;
Timer1.Interval = 1000;
if(time==0)
{
//执行操作
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
lblMess.Text =time -- ;
}
你的是WebForm的还是WinForm的??
{
//从数据库中读取的时间
if(!string.IsNullOrEmpry(this.lblMess.Text))
{
int time = int.Parse(this.lblMess.Text);
this.lblMess.Text = (time--).ToString();
if (time == 0)
{
//执行操作
}
}
}
private int countNum
{
get
{
return ViewState["countNum"] == null ? time : Convert.ToInt32(ViewState["countNum"]);
}
set
{
ViewState["countNum"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Timer1_Tick(object sender, EventArgs e)
{
time = 5;//假如数据库存储的是5秒
this.lblMess.Text = (countNum--).ToString();
if (countNum <0)
{
this.Panel1.Visible = true;
this.lblMess.Text = "您已经成功啦!";
//执行操作
}
}