Click to See Complete Forum and Search --> : ASP Processing on window.close


pgnbn
02-03-2005, 07:38 AM
Hi @ll!

I have a simple asp page with a botton on it with the following code:
onClick='javascript:window.close();'

I would like to keep window closing on click, but now I need that ASP page process a Server operation that can run as a batch leaving the rest of the application running after closing the window.

This operation does the conversion of an HTML just printed document into a PDF document. Using Neevia's Doc Converter COM.

The code for the conversion is:
Set DC = Server.CreateObject("docConverter.docConverterClass")
DC.DocumentOutputFormat = "PDF"
DC.DocumentOutputFolder = myFolder
rv = DC.SubmitFile(FileToConvert, "")

The final statement makes server process the request but doesn't stop execution of the code.

How can I execute de code above and close the window simultaenously?

Thanks in adavance for help,
Pedro

Vince
02-03-2005, 10:56 AM
Hi Pedro

I think that this is really more a JavaScript problem than an ASP.

If you embed a form around your button then you can use the onSubmit event
of the form to send the variables to the server that you want processed then use
JavaScript to close the window.

It is worth noting that this only works with JavaScript generated popup
windows so the user may get a nag screen asking whether they want the
window to be closed.

<html>
<head>
<Script type="text/javascript">
<!--
function SendAndClose(){
window.self.close()
}

-->
</Script>
</head>
<body>
<form name="YourForm" action="MakePDF.asp" onSubmit="SendAndClose()" method="post">
<input id="Hidden1" type="hidden" name="Hidden1" value="MakePDF">
<input type="submit" value="Send and Close">
</form>
</body>
</html>

pgnbn
02-03-2005, 11:55 AM
Hi Vince!

Thanks for your help. I tried your suggestion but I dont want a window to pop-up with tha MakePDF.asp page on it...

Is there any way to process the asp code without opening the asp page on a windows browser?

Thanks,
Pedro

Vince
02-03-2005, 05:06 PM
Hi Pedro

The simple answer is no there is no way to get an ASP page to make a
pdf file without calling the code and you cant do that in strait
HTML, or from the browser side, the only thing you can do is make an
ASP page on the server that makes the pdf file and call it using a
form or a link as I suggested,


Vince

pgnbn
02-04-2005, 01:31 PM
Thanks for your help Vince.

By the way ... I made all work using XMLHTTP.

Code for Submit page:
function Exit(){
window.close();
var sURL = "/asp/MakePDF.asp?sDocName=<%=docum%>";
oXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
oXMLHTTP.open("POST", sURL, true);
oXMLHTTP.send();
}

And asp page:
<%
Dim oXMLResponse
Dim sResponse
Dim sDocName
Dim oMyCOM
sDocName = Request.QueryString("sDocName")

Set oMyCOM = Server.CreateObject("MyCOM")

sResponse = oMyCOM.MakePDF(sDocName)

Set oMyCOM = Nothing

Set oXMLResponse = Server.CreateObject("Msxml2.DOMDocument")
oXMLResponse.async=false
oXMLResponse.loadXML sResponse

Response.ContentType = "text/xml"
oXMLResponse.save Response
Set oXMLResponse=Nothing
%>

Hope this could be useful for you some day.

Greetings,
Pedro