Simple routine. Click a button to increase the time by 6 minutes.
Problem is it only works once unless I click a differnt button.
I thought I could check for PostBack but that did not fix.
Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim varEndTime As Date
varEndTime = lblEndTime.Text
lblEndTime.Text = DateAdd(DateInterval.Minute, 6, varEndTime)
End Sub
I will learn ASP.NET if it kills me!
You can teach an old dog new tricks, but it is very hard work!
Your variable varEndTIme is created brand new inside you button control so this must
only happen when you click the button, after it, the variable should be destroyed as the next click on Button1
will create a brand new variable with same name.
I am not sure what do you want to achieve here !
Are you trying to increase the time by 6 minutes when button is clicked, and repeat itself without the button being clicked again?
The page load event will fire whenever you click a server side button or other control
So every time you click a button your timing thing will run in page load event, to prevent that
so that it runs only for the first time on the page load (and not on button clicks), you should
put that code inside page load, inside the if condition:
if(!Page.IsPostBack)
{
}
Usman Waheed
Marked as answer by gene7135 on Apr 08, 2012 06:51 PM
gene7135
Member
9 Points
61 Posts
Seems to be a state problem
Apr 06, 2012 09:01 PM|LINK
Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim varEndTime As Date varEndTime = lblEndTime.Text lblEndTime.Text = DateAdd(DateInterval.Minute, 6, varEndTime) End SubYou can teach an old dog new tricks, but it is very hard work!
usman400
Contributor
3503 Points
721 Posts
Re: Seems to be a state problem
Apr 07, 2012 03:42 AM|LINK
Your variable varEndTIme is created brand new inside you button control so this must
only happen when you click the button, after it, the variable should be destroyed as the next click on Button1
will create a brand new variable with same name.
I am not sure what do you want to achieve here !
Are you trying to increase the time by 6 minutes when button is clicked, and repeat itself without the button being clicked again?
gene7135
Member
9 Points
61 Posts
Re: Seems to be a state problem
Apr 07, 2012 06:25 PM|LINK
I have a timestamp beling loaded into the label at page_load.
Each time the button is clicked,
For some reason the time will only increase once, unless I press a different button.
You can teach an old dog new tricks, but it is very hard work!
usman400
Contributor
3503 Points
721 Posts
Re: Seems to be a state problem
Apr 08, 2012 06:33 AM|LINK
The page load event will fire whenever you click a server side button or other control
So every time you click a button your timing thing will run in page load event, to prevent that
so that it runs only for the first time on the page load (and not on button clicks), you should
put that code inside page load, inside the if condition:
if(!Page.IsPostBack) { }gene7135
Member
9 Points
61 Posts
Re: Seems to be a state problem
Apr 08, 2012 06:53 PM|LINK
I knew it was simple... Thanks!
yea.. I still don't have a lot of experience yet with ASP.net.
.
You can teach an old dog new tricks, but it is very hard work!