timer to delay execution of event

  • Thread starter Thread starter Jason Shohet
  • Start date Start date
J

Jason Shohet

Lets say I want a button to execute 10 seconds after I press it, not
immediately.
Any ideas how to cause that, in a code-behind. IMO its only server side
code, I don't think javascript needs to get in to the equation (?)
 
you cant do it in codebehind, it would have to be a clientside delay. You
COULD, have the button fire but "wait" (n) seconds before it does something,
but why? I mean what is it you need to get at that needs the delay?
 
I just want to see if it actually works, I'm tinkering. I used it once to
cause a screen refresh w/o a postback. Now I'm trying to see if I can
postpone execution w/ a js func, then have it return to do the rest of the
code. ie:

in page load: this.button8.Attributes.Add("onclick", pr()");

in button8_Click: Response.Write("hi, did this not appear right away?");

in the aspx: <script>
function pr() {
window.setTimeout("pr()", 100);
}
<script>

Alas, it doesn't seem to work. The message appears right away. I figured
the js timer would delay execution on the Response.Write...?
 
You are mixing client and server events up....
You can delay the POST to the server, or you can delay the execution within
the code-behind from within it, but you can't have any interaction between
the two while this is happening.
 
ok i see.... Alright, then I know how to delay the POST to the server from
b4.
What I'm not sure is the 2nd scenario, the code to delay the execution of
the c.behind from within the c.behind?
 
It will be tricky... but traditionally you call the form.submit() in the
timer-delay. In this case though you will have to have it fire the
individual buttons click, unless you can use the page_load and IsPostBack()
 
TY, I'm going to look up timer-delay syntax in c#, and also ask around on
the c# ng.
if it seems way to difficult i'll give up, its more of a curiosity to see if
it can be done
 
It is tough.... you are basically trying to put the thread/process to sleep
(search on "sleep"). There is realy no need to ever do this, or rather
shouldnt be. It's like pausing lifesupport.....
 
Back
Top