Solved

automatically print redirected to the specified Page

Posted on 2004-04-26
8
745 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
 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10919451
Put the response.redirect after the sleep function in the print sub.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now