|
-
May 14th, 2008, 04:14 AM
#1
Thread Starter
Hyperactive Member
[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;
}
}
*****************
VB6,PHP,VS 2005
-
May 14th, 2008, 07:29 AM
#2
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.
-
May 15th, 2008, 03:54 AM
#3
Thread Starter
Hyperactive Member
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;
}
}
*****************
VB6,PHP,VS 2005
-
May 15th, 2008, 03:59 AM
#4
Thread Starter
Hyperactive Member
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;
}
}
*****************
VB6,PHP,VS 2005
-
May 16th, 2008, 01:18 PM
#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.
-
May 16th, 2008, 07:02 PM
#6
Thread Starter
Hyperactive Member
Re: counter
the label is updating and it is inside the updatePanel object
*****************
VB6,PHP,VS 2005
-
May 17th, 2008, 04:40 AM
#7
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|