-
[RESOLVED] counter
in desktop app, this is the code
but in web app it doesnt work, why?
tnx in advance :)
Code:
protected void Page_Load(object sender, EventArgs e)
{
t = 5;
Label1.Text = DateTime.Now.ToString();
Label2.Text = DateTime.Now.ToString();
}
protected void Timer1_Tick(object sender, EventArgs e)
{
Label2.Text = DateTime.Now.ToString();
Label3.Text = t.ToString();
t = t - 1;
if (t == 0)
{
Label3.Text = "gdfgdg";
t = 5;
}
}
-
Re: counter
It doesn't make sense to use a server side timer in an ASP.NET application. The ASP.NET application will just execute the codebehind and output the page. The Timer Tick event is therefore redundant.
You will need to translate the code you want done in the timer tick event to javascript which runs on the client side.
-
Re: counter
i found the solution... pls see below.
hope in some questions for the newbies like me would help in the future
Code:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["TestVal"] == null)
{
Session["TestVal"] = 5;
}
Label1.Text = DateTime.Now.ToString();
Label2.Text = DateTime.Now.ToString();
}
protected void Timer1_Tick(object sender, EventArgs e)
{
Label2.Text = DateTime.Now.ToString();
Session["TestVal"] = Convert.ToString(Convert.ToInt32(Session["TestVal"]) - 1);
Label3.Text = (string)Session["TestVal"];
if (Convert.ToInt32(Label3.Text) == 0)
{
Label3.Text = "gdfgdg";
Session["TestVal"] = 5;
}
}
-
Re: counter
***** RE-SEND
Code:
protected void Page_Load(object sender, EventArgs e)
{
if (Convert.ToInt32(Session["TestVal"]) == 0)
{
Session["TestVal"] = 5;
}
Label1.Text = DateTime.Now.ToString();
Label2.Text = DateTime.Now.ToString();
}
protected void Timer1_Tick(object sender, EventArgs e)
{
Label2.Text = DateTime.Now.ToString();
Session["TestVal"] = Convert.ToString(Convert.ToInt32(Session["TestVal"]) - 1);
Label3.Text = (string)Session["TestVal"];
if (Convert.ToInt32(Label3.Text) == 0)
{
Label3.Text = "5";
Session["TestVal"] = 5;
}
}
-
Re: counter
Again, it won't make a lot of sense, because you're not going to be seeing the changes as the label's text gets updated by the changing values, unless this is in an UpdatePanel in which case it's usually best to divulge such information when asking a question.
-
Re: counter
the label is updating and it is inside the updatePanel object
-
Re: counter