PDA

View Full Version : Pass Variables to ASP or Call an ASP Function from VBScript


cluper
01-28-2004, 08:13 PM
I need to display a VBScript Yes/No MsgBox in an ASP page and return the Yes/No value to an ASP variable or call an ASP function from within the VBScript. See the following code where everything works except the call to the SetUpRptAndVarList("FixList") with a different parameter.


<% if SetUpRptAndVarList("InitialList") = FALSE then
Response.Write "SetUpRptAndVarList=FALSE<br>"
%>
<SCRIPT LANGUAGE="VBScript">
<!--
Dim MsgBoxReturnValue
MsgBoxReturnValue = MsgBox ("<%= strErrorMessage %>" + chr(13) + chr(10) + chr(13) + chr(10) + " Press the Yes button to remove variables until an acceptable length is reached." + chr(13) + chr(10) + " OR " + chr(13) + chr(10) + " Press the No button to return to the Custom Report Selections page." , <%= vbYesNo + vbQuestion + vbDefaultButton1 + vbApplicationModal %> , "Custom Report Specification Length Error" )
If MsgBoxReturnValue = <%= vbYes %> Then
<%= Call SetUpRptAndVarList("FixList") %>
Else
history.go(-3)
End if
-->
</SCRIPT>
<% else
Response.Write "SetUpRptAndVarList=TRUE<br>"
end if %>

Roy Sinclair
01-28-2004, 08:57 PM
You must rethink your page, ASP code runs SERVER SIDE but you obviously want to communicate with the CLIENT. You must remember that the server side code is going to be completely finished executing before the client can do anything with the resulting web page. You cannot interact with the user halfway through the processing of a web page, you can only send the user a web page as one process and then process the user's reply as a separate process. Both of those processes can be in the same web page but they will occur as separate executions of that web page.

Bullschmidt
02-05-2004, 09:17 AM
And here's a little more info about mixing server-side ASP (which gets processed first) with client-side JavaScript.

It's easy to use the value of a VBScript variable in JavaScript:
document.writeln('<%= MyVBScriptVariable %>');

Or here is an example which puts the value of a VBScript variable into a JavaScript alert box:
Response.Write "<script language='JavaScript'>alert('The value is " & MyVBScriptVariable & "');</script>"

But to send the value of a JavaScript variable to VBScript, well that's another story. You could have the JavaScript fill in a hidden form field and then post the form. That way VBScript can pick up the value of the hidden form field with Request.Form("MyFieldName")