i need to delay a response.wrtie

Last post 11-02-2006 2:20 PM by asp_eater. 15 replies.

Sort Posts:

  • i need to delay a response.wrtie

    10-29-2006, 3:28 PM
    • Loading...
    • thechasboi
    • Joined on 07-09-2003, 4:10 PM
    • Posts 9
    I have this application and I need to delay a response.write from occuring.  I would appreciate some enlightenment on this.  Thanks for the help in advance.
    Chas
  • Re: i need to delay a response.wrtie

    10-29-2006, 3:45 PM
    • Loading...
    • vcsjones
    • Joined on 04-18-2006, 8:53 PM
    • Falls Church, VA
    • Posts 3,989
    • Moderator
      TrustedFriends-MVPs
    Why would you want to do that? What scenario is that useful? I suppose to could start the method in another thread and put a timer on the thread, but I see no practicality to it.
    Cheers,
           Kevin Jones


  • Re: i need to delay a response.wrtie

    10-29-2006, 3:51 PM
    • Loading...
    • mbanavige
    • Joined on 11-06-2003, 8:29 AM
    • New England, USA
    • Posts 7,705
    • Moderator
      TrustedFriends-MVPs

    More often than not, Response.Write is something to be completely avoided with asp.net.
    Response.Write occurs outside of the page lifecycle and trying to generate content with it, that is in sync with the page, is usually not going to work.

    use a Label or Literal control to assign the text that you needed to output with response.write. 

    if a label or literal is not possible, then please elaborate on what you're trying to accomplish.

    Mike Banavige
    ~~~~~~~~~~~~
    Dont forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: i need to delay a response.wrtie

    10-29-2006, 3:53 PM
    • Loading...
    • thechasboi
    • Joined on 07-09-2003, 4:10 PM
    • Posts 9

    vcsjones

    I have this app that rewrites some javascript to an opener but the thing is that I need the rewrite to wait a about 20 seconds it is a timing issue wth a file.  I have already tried the exists thing but if the file is already in the folder and is only being rewritten then this methiod does not work.  That is the scenerio and this is why i need the response.write to be timed out for like 20 seconds it is the file issue.  Thanks for the help. 

    Chas
  • Re: i need to delay a response.wrtie

    10-29-2006, 4:53 PM
    • Loading...
    • vcsjones
    • Joined on 04-18-2006, 8:53 PM
    • Falls Church, VA
    • Posts 3,989
    • Moderator
      TrustedFriends-MVPs

    Why not put the timer in the JavaScript and write it immediately. Mbanavige is correct, using Response.Write is something that should be avoided at all costs.

    Cheers,
           Kevin Jones


  • Re: i need to delay a response.wrtie

    10-29-2006, 5:53 PM
    • Loading...
    • mbanavige
    • Joined on 11-06-2003, 8:29 AM
    • New England, USA
    • Posts 7,705
    • Moderator
      TrustedFriends-MVPs

    i'm not sure your describing your problem clearly enough [for me].
    writing javascript to an opener -> do you mean "opener" as in "window.opener" as in a popup?

    is sounds like you have a couple steps running asynchronously (possible because of a popup?) and you are intending to introduce an artificial delay in an effor to insure that one step finishes last.  if that's what you're doing - i'd discourage it.  the artificial delay may end up not being long enough [occasionally] based on server load etc...  if you need your steps to be synchronous, then i'd code it that way.

    perhaps you can give us some psuedo code.

    1. do this
    2. do that
    3.     launch popup (which creates a file)
    4. get file created by popup (fails if step 3 isnt finished yet...)

    i'm still trying to grasp exactly what you're doing...

    Mike Banavige
    ~~~~~~~~~~~~
    Dont forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: i need to delay a response.wrtie

    10-29-2006, 6:10 PM
    • Loading...
    • thechasboi
    • Joined on 07-09-2003, 4:10 PM
    • Posts 9
    I have tried the setTimeout() function but it does not seem to execute the line of code inside the function no matter what it is, I tried an alert in it, just in case but that is not working either.  What I really need is to delay the response.write.  I have tried several different means via javascript like calling a function on a delay not working for some reason.  So the answer I need is the one for delaying the response.write.  Thanks for the help in advance.
    Chas
  • Re: i need to delay a response.wrtie

    10-29-2006, 6:12 PM
    • Loading...
    • vcsjones
    • Joined on 04-18-2006, 8:53 PM
    • Falls Church, VA
    • Posts 3,989
    • Moderator
      TrustedFriends-MVPs
    In your case you cannot delay the response.write. because if you delay it, it will just freeze up the page until all threads are done. You need a client-side solution, this will not work via server side.
    Cheers,
           Kevin Jones


  • Re: i need to delay a response.wrtie

    10-30-2006, 3:31 AM
    • Loading...
    • thechasboi
    • Joined on 07-09-2003, 4:10 PM
    • Posts 9

    vscjones

     

    I know it will hold up the page and it is exceptable but the way this little application is designed this is the only way to get it to work totally properly.  This is the only way this application will work by the way.  I need a server side solution.  That is it, please send me a link or something.  I have tried and did not find anything that would remotely help me in my situation.  If you have a way to delay this I would appreciate the answer.  I have some ideas but do not want to make it CPU intensive.  I remember seeing this article one day about regular ASP in how to delay something is to do a check for existance of a file, or something to this sort but can not find the same article again.  I do not know if there is any built in function in ASP.net to dothis if so please enlighten me.  Thanks for the help.

    Chas
  • Re: i need to delay a response.wrtie

    10-30-2006, 5:16 AM
    • Loading...
    • e_screw
    • Joined on 10-20-2004, 1:22 PM
    • Women, Guitar, Russia, Billiards, Nature, .NET
    • Posts 3,852

    You can stop the Response.Write for a while by using the Thread.Sleep(milliseconds).

    This is how it goes:

    System.Threading.Thread.Sleep(5000);
    Response.Write("Rendered after 5 seconds");

    Thanks

    Mark post(s) as "Answer" that helped you

    Electronic Screw
    Website||Blog||Dub@i.net
  • Re: i need to delay a response.wrtie

    10-30-2006, 10:31 AM
    • Loading...
    • vcsjones
    • Joined on 04-18-2006, 8:53 PM
    • Falls Church, VA
    • Posts 3,989
    • Moderator
      TrustedFriends-MVPs
    But the problem with that is, it won't have the effect he is looking for. He wants it to render completely, then have a delayed javascript. With that method, the page won't render at all until the time is up. He needs a client-side solution. It simply cannot be done at the server side level effectively. The options are AJAX or Javascript.
    Cheers,
           Kevin Jones


  • Re: i need to delay a response.wrtie

    10-30-2006, 12:04 PM
    • Loading...
    • SuperGhost
    • Joined on 12-29-2005, 4:58 PM
    • Palmdale CA, USA
    • Posts 404

    I agree with vcsjones,

    The only way to get the effect you want is to use client-side scripting.

    Are you sure you have used the javascript timeout function properly? Here is a link with an example: http://www.htmlite.com/JS018.php

    And check this out as well:

    <script language="javascript" type="text/javascript">
    <!--
    function mytimer() {
    setTimeout("alert('Three seconds has passed.');",3000);
    }
    // -->
    </script>

     Then in your ASP.NET Code on Page_Load you can use:

    ClientScript.RegisterClientScriptBlock(Me.GetType(), "js", "mytimer();", True)
     
    ** Hope this helps!

    DennyDotNet.com
  • Re: i need to delay a response.wrtie

    10-30-2006, 12:13 PM
    • Loading...
    • e_screw
    • Joined on 10-20-2004, 1:22 PM
    • Women, Guitar, Russia, Billiards, Nature, .NET
    • Posts 3,852

    Yeah thats true.

    Thanks

    Mark post(s) as "Answer" that helped you

    Electronic Screw
    Website||Blog||Dub@i.net
  • Re: i need to delay a response.wrtie

    11-01-2006, 3:04 PM
    • Loading...
    • asp_eater
    • Joined on 09-28-2006, 5:22 PM
    • Westlake Ohio
    • Posts 8

    Thank you to every one for the help. I tried the "System.Threading.Thread.Sleep(5000)" but ist does not seem to be pausing.  I am beside myself on this one.  I tried several in a row tried to call it from a sub tried ten different things going nuts here.  I unfortunately undoughtedly need something that will delay the response.write.  OK, maybe a little more detail is needed.  This application is an aspx page.  The page first loads and you make some choices and upload an image.  Based upon your choice some javascript is made into a string then here is the response.write coming into play.  After making your choices the page is refreshed and some actions are taken on your file and info you uploaded and choices made.  The javascript is then written to the page via a response.write, but i need this to be delayed about 5 seconds until the picture and other executions are taken care of. 

     

    Thanks again for the help. 

    Charley George
    Programmer/Consultant
  • Re: i need to delay a response.wrtie

    11-01-2006, 4:02 PM
    • Loading...
    • vcsjones
    • Joined on 04-18-2006, 8:53 PM
    • Falls Church, VA
    • Posts 3,989
    • Moderator
      TrustedFriends-MVPs
    Again, as several other posts in the this post have said, you can NOT delay a Response.Write.
    Cheers,
           Kevin Jones


Page 1 of 2 (16 items) 1 2 Next >