Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I call a Sub on UnLoad but my Public Variable above is reset?

Status
Not open for further replies.

wmd3

Programmer
Jan 22, 2002
37
US
Example:

<%

Dim bln

bln = False

Sub Process()
bln = True
End Sub

Sub DoOnUnload()
If bln = True Then
'This is never hit.
End If
End Sub

%>

<html>
<body OnUnload=&quot;<%DoOnUnload%>&quot;>
Process
</body>
</html>

I am new to VBScript, and if I am missing something I would like to try to understand it.
 
Sorry,

I execute it when someone presses a button on my form and then I move on to the next page (triggering the OnUnload).

But, they can also press a different button that doesn't execute Process and continue to the next page.
 
I have done some more investigating and discoved that the OnUnload is running before the Sub Process I am calling from an OnClick of a button.

-------------------------------
<%

Dim Accepted
Accepted = 0

Sub Process()
Dim cn
Accepted = 1
set cn = GetDatabaseConn()
cn.Execute &quot;(Some SQL statement here.)&quot;
cn.close
set cn = nothing
Response.Write &quot;Call Window.Close()&quot;
End Sub

Sub ClosePage()
Response.Write &quot;Call Window.Close()&quot;
End Sub

Sub PageUnload()
Dim cn
set cn = GetDatabaseConn()
cn.Execute &quot;(SQL using my Variable here.)&quot; & Accepted
cn.close
set cn = nothing
End Sub

%>

<html>

<body OnUnload='<%PageUnload%>'>

<form action=&quot;&quot; method=&quot;post&quot; name=&quot;frmProcess&quot;>
<input type=&quot;BUTTON&quot; value=&quot;Accept&quot; language=&quot;VBScript&quot; onclick=&quot;<%Process%>&quot;>
<input type=&quot;BUTTON&quot; value=&quot;Close&quot; language=&quot;VBScript&quot; onclick=&quot;<%ClosePage%>&quot;>

</form>

</body>
</html>

---------------------------
This is an example of what I am doing. Is there anything I can change to do it better or to get my desired results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top