Solved

automatically print redirected to the specified Page

Posted on 2004-04-26
8
763 Views
Last Modified: 2007-12-19
Hi,

i am usin w2k  service pack 3 and explorer  ver.5.

I have an search page. when user enter search id and submit the result will be printed automaticaly without any print dialo box to appear. the code is workin fine. Here i want to return to search.asp automatically after printin or bein displayed the searchresult.asp page for some time and printin. when i use "response.redirect" anywhere in the searchresult.asp, when user click submit from search.asp, s/he cannot print the result.  It is just redirected to search.asp wihtout printin. if not usin response.redirect then the result will be printed out automatically. how can return to the serach.asp after printin or even the result is displayed there for a while and bein printed.

searchResult.asp.

<html>
<head>
<script language="VBScript">
SUB Print()
    OLECMDID_PRINT = 6
    OLECMDEXECOPT_DONTPROMPTUSER = 2
    OLECMDEXECOPT_PROMPTUSER = 1
    document.body.focus()
    on error resume next
    call IEWB.ExecWB (OLECMDID_PRINT, -1)
    if err.number <> 0 then
        alert "Nothing Printed"
    end if
END SUB
</script>

<%set con = server.createObject ("connection")
con.open "studentsList"

set rst = server.createobject("adodb.recordset")
rst.open "select * from student where id='" &Request ("txtID")& "'",con

</head>
     <body onload="print()">
          <object id="IEWB" width="0" height="0" classid="clsid:8856F961-340A-11D0-A96B-00C04FD705A2">
          </object>
          <table><tr><td>Name</td><td><rst("Name")%></td>
<td>School</td><td><%rst("school")%></td></tr></table>
     </body>
</html>
0
Comment
Question by:ayha1999
  • 4
  • 4
8 Comments
 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10917661
Im not entirely sure I understand your question, but you could put a sleep function in your code to make the page wait before redirecting:

function tsp_sleep(var)
Dim MaxSleep
'Sleep for 20 seconds
MaxSleep = 20
    if var < 1 then
    var = 1
    elseif var > MaxSleep then
    var = MaxSleep
    end if
    dim x
    x = timer
    do until x + var = timer
    ' sleep
    loop
 end function


Then in your Print Func, put the sleep at  the end to make the page wait.

SUB Print()
    OLECMDID_PRINT = 6
    OLECMDEXECOPT_DONTPROMPTUSER = 2
    OLECMDEXECOPT_PROMPTUSER = 1
    document.body.focus()
    on error resume next
    call IEWB.ExecWB (OLECMDID_PRINT, -1)
    if err.number <> 0 then
        alert "Nothing Printed"
    end if
'Make it wait 10 seconds
tsp_sleep(10)
END SUB
</script>

0
 
LVL 7

Author Comment

by:ayha1999
ID: 10919423
Hi Slimshaaney,

, but you could put a sleep function in your code to make the page wait before redirecting:

what i want is, once user click submit from search.asp page, the searchresult.asp page shoud be printed out and then redirected to search.asp.

could you please check tsp_sleep function whcih show me script error. and where can i put response.redirect "search.asp".  

<html>
<head>
<@ language="VBScript">
<SCRIPT LANGUAGE=javascript>

function tsp_sleep(var)
Dim MaxSleep
'Sleep for 20 seconds
MaxSleep = 20
    if var < 1 then
    var = 1
    elseif var > MaxSleep then
    var = MaxSleep
    end if
    dim x
    x = timer
    do until x + var = timer
    ' sleep
    loop
 end function      
      //-->
</SCRIPT>


<script language="VBScript">
SUB Print()
    OLECMDID_PRINT = 6
    OLECMDEXECOPT_DONTPROMPTUSER = 2
    OLECMDEXECOPT_PROMPTUSER = 1
    document.body.focus()
    on error resume next
    call IEWB.ExecWB (OLECMDID_PRINT, -1)
    if err.number <> 0 then
        alert "Nothing Printed"
    end if
   
    'Make it wait 10 seconds
tsp_sleep(10)

END SUB
</script>


<%set con = server.createObject ("connection")
con.open "studentsList"

set rst = server.createobject("adodb.recordset")
rst.open "select * from student where id='" &Request ("txtID")& "'",con

</head>
<body onload="print()">
          <object id="IEWB" width="0" height="0" classid="clsid:8856F961-340A-11D0-A96B-00C04FD705A2">
          </object>
          <table><tr><td>Name</td><td><rst("Name")%></td>
<td>School</td><td><%rst("school")%></td></tr></table>
</body>
</html>

ayha1999.
0
 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10919443
the function is a vbscript function not a javascript one:

<SCRIPT LANGUAGE=vbcript>

function tsp_sleep(var)
Dim MaxSleep
'Sleep for 20 seconds
MaxSleep = 20
    if var < 1 then
    var = 1
    elseif var > MaxSleep then
    var = MaxSleep
    end if
    dim x
    x = timer
    do until x + var = timer
    ' sleep
    loop
 end function    
     //-->
</SCRIPT>
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10919451
Put the response.redirect after the sleep function in the print sub.
0
 
LVL 7

Author Comment

by:ayha1999
ID: 10920002
Hi Slimshaaney,

Put the response.redirect after the sleep function in the print sub.

Ok, i changed script to vbscript. this time i get a mesage that "a script on this page is causing Internet Explorer torun slowly. if it continues to run, your computer may become unresponsive. Do you wanto to abort the script?" I clicked "No". then Explorer is freezing and it never redirecting to the search.asp but i prints. how can i avaoid this message and returning back to search.asp page after specied time interval.

the following is the modified code.

<SCRIPT LANGUAGE="vbScript">

function tsp_sleep(var)
Dim MaxSleep
'Sleep for 20 seconds
MaxSleep = 20
    if var < 1 then
    var = 1
    elseif var > MaxSleep then
    var = MaxSleep
    end if
    dim x
    x = timer
    do until x + var = timer
    ' sleep
    loop
 end function      
 
</script>
<script language="vbscript">

SUB Print()
    OLECMDID_PRINT = 6
    OLECMDEXECOPT_DONTPROMPTUSER = 2
    OLECMDEXECOPT_PROMPTUSER = 1
    document.body.focus()
    on error resume next
    call IEWB.ExecWB (OLECMDID_PRINT, -1)
    if err.number <> 0 then
        alert "Nothing Printed"
    end if
   
    'Make it wait 10 seconds
tsp_sleep(10)

Response.Redirect "inHist.asp"

END SUB

</script>

ayha1999.
0
 
LVL 11

Accepted Solution

by:
Slimshaneey earned 250 total points
ID: 10920040
Hmmm.
Try changing the sleep function to this...

Dim MaxSleep
'Sleep for 20 seconds
MaxSleep = 20
    if var < 1 then
    var = 1
    elseif var > MaxSleep then
    var = MaxSleep
    end if
    dim x
    x = timer
    do until (x + var) <= timer
    ' sleep
    loop
 end function  
0
 
LVL 7

Author Comment

by:ayha1999
ID: 10920271
Hi Shamney,

this time a script error in line 17 after that print dialog appears. i dont want print dialog to appear. i think the script error appears because end funtion is there without function.

the following is the modified code.

<SCRIPT LANGUAGE="vbScript">

Dim MaxSleep
'Sleep for 20 seconds
MaxSleep = 20
    if var < 1 then
    var = 1
    elseif var > MaxSleep then
    var = MaxSleep
    end if
    dim x
    x = timer
    do until (x + var) <= timer
    ' sleep
    loop
 end function  

SUB Print()
    OLECMDID_PRINT = 6
    OLECMDEXECOPT_DONTPROMPTUSER = 2
    OLECMDEXECOPT_PROMPTUSER = 1
    document.body.focus()
    on error resume next
    call IEWB.ExecWB (OLECMDID_PRINT, -1)
    if err.number <> 0 then
        alert "Nothing Printed"
    end if
   
    'Make it wait 10 seconds
tsp_sleep(10)

END SUB

Response.Redirect "inHist.asp"
</script>


ayha1999.
0
 
LVL 7

Author Comment

by:ayha1999
ID: 10920492
Hi Shamney,

I fixed funtion problem. now again i get the previous message "a script on this page is causing Internet Explorer torun slowly. if it continues to run, your computer may become unresponsive. Do you wanto to abort the script?"  when i clicked no. it prints but another scripts errors comes, "response.redirect... error.....

ayha1999.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question