timer to delay execution of event

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 (?)
 
C

Curt_C [MVP]

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?
 
J

Jason Shohet

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...?
 
C

Curt_C [MVP]

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.
 
J

Jason Shohet

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?
 
C

Curt_C [MVP]

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()
 
J

Jason Shohet

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
 
C

Curt_C [MVP]

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.....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top