Link to home
Start Free TrialLog in
Avatar of ayha1999
ayha1999

asked on

automatically print redirected to the specified Page

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>
Avatar of Slimshaneey
Slimshaneey
Flag of United Kingdom of Great Britain and Northern Ireland image

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>

Avatar of ayha1999
ayha1999

ASKER

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.
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>
Put the response.redirect after the sleep function in the print sub.
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.
ASKER CERTIFIED SOLUTION
Avatar of Slimshaneey
Slimshaneey
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.