473,320 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to go from VB in a page to ASP in another page and come back

Hi,
This is 'test.htm'
---------------

<form name=totd>
<input name="ud" type="hidden" value="" >
</form>

sub dag_onchange()
'dag is a Select
dat=dag.value
if dat<>"99" then
'pass that value to ASP file via a form
document.getElementById("ud").value=dat
ins.action="test2.asp"
ins.method="post"
ins.submit

'i need the value totd generated by 'test2.asp' and then come back and
continue here ...
if totd=0 then.
......
end if
.........
end sub
table 'test2.asp'
--------------
<%
dat=request.form("ud")
set objdc = Server.CreateObject("ADODB.Connection")
objdc.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source
=c:\access\test.mdb")
sql = "select lcount(uur) as totdag from studres
set rs=Server.CreateObject("ADODB.recordset")
rs.open sql, objdc, 3, 3
rec=rs.recordcount
if rec > 0 then
totd=rs.Fields("totdag").Value
end if
%>

Now i would like to go back to 'test.asp' with the value of totd, and even
in the sub dag_change() procedure
..
Thanks for help
André
Jul 19 '05 #1
4 1486

"Andre" <aa@no.it> wrote in message
news:eM**************@TK2MSFTNGP10.phx.gbl...
Hi,
This is 'test.htm'
---------------

<form name=totd>
<input name="ud" type="hidden" value="" >
</form>

sub dag_onchange()
'dag is a Select
dat=dag.value
if dat<>"99" then
'pass that value to ASP file via a form
document.getElementById("ud").value=dat
ins.action="test2.asp"
ins.method="post"
ins.submit

'i need the value totd generated by 'test2.asp' and then come back and
continue here ...
if totd=0 then.
.....
end if
........
end sub
table 'test2.asp'
--------------
<%
dat=request.form("ud")
set objdc = Server.CreateObject("ADODB.Connection")
objdc.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source
=c:\access\test.mdb")
sql = "select lcount(uur) as totdag from studres
set rs=Server.CreateObject("ADODB.recordset")
rs.open sql, objdc, 3, 3
rec=rs.recordcount
if rec > 0 then
totd=rs.Fields("totdag").Value
end if
%>

Now i would like to go back to 'test.asp' with the value of totd, and even
in the sub dag_change() procedure
.
Thanks for help
André


Andre --

You can't call server-side script (as in an ASP script) from client-side
event code without a third-party tool. You have to either post your form or
get the desired script with a querystring for the server to know you want it
to do something.

You could do something like this in just one ASP:

** file test.asp **
<% option explicit %>
<%
dim strMethod, cn, strSQL, rs, dat, totd, IsPostback

' initialize variables so their purpose is clear
' and you don't have problems later if they're not initialized
IsPostback = False
strMethod = ""
dat = ""
totd = CLng(0) ' since totd holds a long later on
' also guarantees totd has a long integer value even if it isn't
changed

with Request
strMethod = LCase(.servervariables("REQUEST_METHOD"))
if strMethod = "post" then
IsPostback = True
' Assuming you're using IIS 5 or later, you can use
Server.Execute to call another script.
' However, for this example it'll be done in-line in this
script.
dat = .form("ud") ' you don't indicate just what 'dat' is used
for
set cn = createobject("ADODB.Connection")
set rs = createobject("ADODB.Recordset")
strSQL = "select count(uur) as totdag from studres" ' lcount??
cn.Open("provider=Microsoft.Jet.OLEDB.4.0; Data
Source=c:\access\test.mdb")
with rs
.cursortype = adOpenStatic ' 3
.locktype = adLockReadOnly ' 1
.activeconnection = cn
.open strSQL
.activeconnection = nothing
' if you are only reading, always close the connection
immediately
' only keep it open if you will be doing more work right
then
cn.close
if .recordcount > 0 then
' no need to assign recordcount unless you will use it
more than once
totd = CLng(.Fields("totdag").Value) ' casting numerics
is a good idea
end if
.close
end with
set rs = nothing
set cn = nothing
end if
end with
%>
<html>
<head>
</head>
<body>
<form <form name="totd" method="post">
<input name="ud" type="hidden" value="">
<% if 1 = 0 then %>
comment: you can use the dropdown's change event as you had
to do the assignment and submit, but you and just as easily get
its value as .form("thedropdownsname") from the script's
request object
<% end if %>
</form>
<% if IsPostback then %><br>The value of 'totd' is:&nbsp;<%=totd%><br><%
end if %>
</body>
</html>

Alternatively, you could put your processing code in a Function within the
script, or in another file containing common routines you use and use an
#include directive in pages you want it.

Alan
Jul 19 '05 #2
thanks ...

"J. Alan Rueckgauer" <vo**@dev.nul> wrote in message
news:up*************@tk2msftngp13.phx.gbl...

"Andre" <aa@no.it> wrote in message
news:eM**************@TK2MSFTNGP10.phx.gbl...
Hi,
This is 'test.htm'
---------------

<form name=totd>
<input name="ud" type="hidden" value="" >
</form>

sub dag_onchange()
'dag is a Select
dat=dag.value
if dat<>"99" then
'pass that value to ASP file via a form
document.getElementById("ud").value=dat
ins.action="test2.asp"
ins.method="post"
ins.submit

'i need the value totd generated by 'test2.asp' and then come back and
continue here ...
if totd=0 then.
.....
end if
........
end sub
table 'test2.asp'
--------------
<%
dat=request.form("ud")
set objdc = Server.CreateObject("ADODB.Connection")
objdc.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source
=c:\access\test.mdb")
sql = "select lcount(uur) as totdag from studres
set rs=Server.CreateObject("ADODB.recordset")
rs.open sql, objdc, 3, 3
rec=rs.recordcount
if rec > 0 then
totd=rs.Fields("totdag").Value
end if
%>

Now i would like to go back to 'test.asp' with the value of totd, and even in the sub dag_change() procedure
.
Thanks for help
André

Andre --

You can't call server-side script (as in an ASP script) from client-side
event code without a third-party tool. You have to either post your form

or get the desired script with a querystring for the server to know you want it to do something.

You could do something like this in just one ASP:

** file test.asp **
<% option explicit %>
<%
dim strMethod, cn, strSQL, rs, dat, totd, IsPostback

' initialize variables so their purpose is clear
' and you don't have problems later if they're not initialized
IsPostback = False
strMethod = ""
dat = ""
totd = CLng(0) ' since totd holds a long later on
' also guarantees totd has a long integer value even if it isn't
changed

with Request
strMethod = LCase(.servervariables("REQUEST_METHOD"))
if strMethod = "post" then
IsPostback = True
' Assuming you're using IIS 5 or later, you can use
Server.Execute to call another script.
' However, for this example it'll be done in-line in this
script.
dat = .form("ud") ' you don't indicate just what 'dat' is used for
set cn = createobject("ADODB.Connection")
set rs = createobject("ADODB.Recordset")
strSQL = "select count(uur) as totdag from studres" ' lcount?? cn.Open("provider=Microsoft.Jet.OLEDB.4.0; Data
Source=c:\access\test.mdb")
with rs
.cursortype = adOpenStatic ' 3
.locktype = adLockReadOnly ' 1
.activeconnection = cn
.open strSQL
.activeconnection = nothing
' if you are only reading, always close the connection
immediately
' only keep it open if you will be doing more work right
then
cn.close
if .recordcount > 0 then
' no need to assign recordcount unless you will use it
more than once
totd = CLng(.Fields("totdag").Value) ' casting numerics is a good idea
end if
.close
end with
set rs = nothing
set cn = nothing
end if
end with
%>
<html>
<head>
</head>
<body>
<form <form name="totd" method="post">
<input name="ud" type="hidden" value="">
<% if 1 = 0 then %>
comment: you can use the dropdown's change event as you had
to do the assignment and submit, but you and just as easily get
its value as .form("thedropdownsname") from the script's
request object
<% end if %>
</form>
<% if IsPostback then %><br>The value of 'totd' is:&nbsp;<%=totd%><br><% end if %>
</body>
</html>

Alternatively, you could put your processing code in a Function within the
script, or in another file containing common routines you use and use an
#include directive in pages you want it.

Alan

Jul 19 '05 #3
but if i understand your code, the value from ASP is put outside the SUB. Is
it not possible to get that value within the SUB dag_onchange(), because
that value must be tested in the SUB and determines the visibility style of
another SELECT in the same page etc ...
If i get that value outside SUB dag_onchange, how can i make the other
select visible?

thanks again



"J. Alan Rueckgauer" <vo**@dev.nul> wrote in message
news:up*************@tk2msftngp13.phx.gbl...

"Andre" <aa@no.it> wrote in message
news:eM**************@TK2MSFTNGP10.phx.gbl...
Hi,
This is 'test.htm'
---------------

<form name=totd>
<input name="ud" type="hidden" value="" >
</form>

sub dag_onchange()
'dag is a Select
dat=dag.value
if dat<>"99" then
'pass that value to ASP file via a form
document.getElementById("ud").value=dat
ins.action="test2.asp"
ins.method="post"
ins.submit

'i need the value totd generated by 'test2.asp' and then come back and
continue here ...
if totd=0 then.
.....
end if
........
end sub
table 'test2.asp'
--------------
<%
dat=request.form("ud")
set objdc = Server.CreateObject("ADODB.Connection")
objdc.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source
=c:\access\test.mdb")
sql = "select lcount(uur) as totdag from studres
set rs=Server.CreateObject("ADODB.recordset")
rs.open sql, objdc, 3, 3
rec=rs.recordcount
if rec > 0 then
totd=rs.Fields("totdag").Value
end if
%>

Now i would like to go back to 'test.asp' with the value of totd, and even in the sub dag_change() procedure
.
Thanks for help
André

Andre --

You can't call server-side script (as in an ASP script) from client-side
event code without a third-party tool. You have to either post your form

or get the desired script with a querystring for the server to know you want it to do something.

You could do something like this in just one ASP:

** file test.asp **
<% option explicit %>
<%
dim strMethod, cn, strSQL, rs, dat, totd, IsPostback

' initialize variables so their purpose is clear
' and you don't have problems later if they're not initialized
IsPostback = False
strMethod = ""
dat = ""
totd = CLng(0) ' since totd holds a long later on
' also guarantees totd has a long integer value even if it isn't
changed

with Request
strMethod = LCase(.servervariables("REQUEST_METHOD"))
if strMethod = "post" then
IsPostback = True
' Assuming you're using IIS 5 or later, you can use
Server.Execute to call another script.
' However, for this example it'll be done in-line in this
script.
dat = .form("ud") ' you don't indicate just what 'dat' is used for
set cn = createobject("ADODB.Connection")
set rs = createobject("ADODB.Recordset")
strSQL = "select count(uur) as totdag from studres" ' lcount?? cn.Open("provider=Microsoft.Jet.OLEDB.4.0; Data
Source=c:\access\test.mdb")
with rs
.cursortype = adOpenStatic ' 3
.locktype = adLockReadOnly ' 1
.activeconnection = cn
.open strSQL
.activeconnection = nothing
' if you are only reading, always close the connection
immediately
' only keep it open if you will be doing more work right
then
cn.close
if .recordcount > 0 then
' no need to assign recordcount unless you will use it
more than once
totd = CLng(.Fields("totdag").Value) ' casting numerics is a good idea
end if
.close
end with
set rs = nothing
set cn = nothing
end if
end with
%>
<html>
<head>
</head>
<body>
<form <form name="totd" method="post">
<input name="ud" type="hidden" value="">
<% if 1 = 0 then %>
comment: you can use the dropdown's change event as you had
to do the assignment and submit, but you and just as easily get
its value as .form("thedropdownsname") from the script's
request object
<% end if %>
</form>
<% if IsPostback then %><br>The value of 'totd' is:&nbsp;<%=totd%><br><% end if %>
</body>
</html>

Alternatively, you could put your processing code in a Function within the
script, or in another file containing common routines you use and use an
#include directive in pages you want it.

Alan

Jul 19 '05 #4

"Andre" <aa@no.it> wrote in message
news:eZ**************@TK2MSFTNGP12.phx.gbl...
but if i understand your code, the value from ASP is put outside the SUB. Is it not possible to get that value within the SUB dag_onchange(), because
that value must be tested in the SUB and determines the visibility style of another SELECT in the same page etc ...
If i get that value outside SUB dag_onchange, how can i make the other
select visible?

thanks again

[snip]

The way you have described it, "Sub dag_onchange" is client-side event
script, meaning it is executed in the browser, not the server. The server
has absolutely no knowledge of events that occur in the browser. It only
knows something is going on when the form is submitted back to the server.
The server can only leave results for the client through <%=...%> script
tags that are replaced when the server prepares the page, not after it is
received in the browser. For instance, if you have this in a client event
script block:

If dag.value = "<%=AServerSideVariable%>" then
'do something
End If

the result you'll see if you view the source in the browser would be
something like:

If dag.value = "This is what the server left." then

You can't do a direct comparison such as:

If dag.value = AServerSideVariable then

In other words, in the client script you are not comparing your variable
against a server variable, you are comparing the client variable to a
literal representing an actual *value* left by the server. From the client
perspective, it is the same as if you typed the value in yourself.

Try this sample to get an idea of what I mean (the code's formatted a bit
awkwardly, but that's to avoid line-wrap problems):

**** begin sample file "testforandre.asp" ****

<% option explicit %>
<%
dim IsPostback, strMethod, TextOptionPickVal
dim TextForOptionPick, TextForTextbox
dim MagicWord, UsedMagicWord

IsPostback = false
strMethod = ""
TextForOptionPick = ""
TextForTextbox = ""
MagicWord = "boo"
UsedMagicWord = false

with request
strMethod = lcase(.servervariables("REQUEST_METHOD"))
if strMethod = "post" then
IsPostback = true
TextOptionPickVal = .form("D1")
select case TextOptionPickVal
case ""
TextForOptionPick = "Nothing"
case "1"
TextForOptionPick = "the first item"
case "2"
TextForOptionPick = "the second item"
case "3"
TextForOptionPick = "the third item"
end select
TextForTextbox = trim(.Form("T1"))
If TextForTextbox = "" then
TextForTextbox = "<b>You didn't type anything.</b>"
Else
if instr(TextForTextbox, MagicWord) > 0 then
UsedMagicWord = true
end if
TextForTextbox = "You typed: " & _
"<font color=""red""><b>" & _
TextForTextbox & "</b></font>"
end if
end if
end with
%>
<html>
<head>
<title>Test Posting Script for Andre</title>
</head>
<body>
<form method="POST">
<p>Hello, Andre. Postback is <%=IsPostback%>.</p>

<% if IsPostBack then 'form was submitted %>
<p>You picked <%=TextForOptionPick%>
from the list (<%=TextOptionPickVal%>)</p>
<p><%=TextForTextbox%></p>
<p><% if UsedMagicWord then %>
You typed the magic word!
<% else %>
You did not type the magic word.
<% end if %></p>
<p>Is it making more sense now?</p>
<p>(use 'back' to try it again)</p>

<% else 'form wasn't submitted %>

<p>Fill out the form and click submit.</p>
<p>Pick one of these:
<select size="1" name="D1">
<option value="">(Please pick)</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">A Third Option</option>
</select></p>
<p>Type something here:
<input type="text" name="T1" size="20"></p>
<% if not UsedMagicWord then %>
(Try typing "<%=MagicWord%>" anywhere in the
textbox and see what happens.)
<% end if %>
<p>
<input type="submit" value="Submit" name="B1"></p>

<% end if %>
</form>
</body>
</html>

*** end of "testforandre.asp" ****

Run the page. In the browser, view | source both before and after you
submit it and compare it to the script code. Try it a number of times with
different inputs. You'll be able to see where the server variables were
inserted, and how the logic in the client script determined what to display
based on what you entered or whether you had submitted the form.

While I did not show you actual interaction between client event script and
the server, the principles are essentially the same: The server can work
with values you submit via form input controls, and you get back literal
values from the server that you can test in the client's script. However,
you can't directly mix the two.

I hope this clears it up a bit more.

Alan
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Bill H | last post by:
I have a routine that displays 60 items (with thumbnails) per page. You can click any item and displays a new page with item details. When the user back pages it runs the query again to display all...
16
by: Dave Smithz | last post by:
Hi, In summary: I want to a form to submit information via a HTTP POST, however, when using Internet Explorer I want to be able to use the back button and all the information retained....
15
by: wk6pack | last post by:
Hi, I have a problem and not quite how to go about solving it. I have a form written in asp. I wish to submit the form and have the server return back to the same page without actually...
1
by: Marc | last post by:
I want to write a C#/ASP.NET application where a user can go to a web page, start running a job, close their browser, and then come back later and see the results. The purpose for this application is...
12
by: VB Programmer | last post by:
I know some sites will display the following message if you click on the BACK button in your browser. How do I implement this feature? Warning: Page has Expired The page you requested was...
8
by: Galina | last post by:
Hello I have 6 dependent list boxes on my ASP page:  Faculty;  Lecturer;  Course;  Course occurrence;  Group;  Week commencing date. When faculty is selected, lists of lecturers and...
23
by: Peter | last post by:
I have a problem with a page show_image.asp that returns a jpg image under Windows XP Pro SP2. The page sets content type as: Response.ContentType = "image/jpg" While this works perfectly fine...
1
by: mbruyns | last post by:
i have been trying (and sometimes succeeding) to use the modalpopupextender to show various panels of controls on my asp pages. the strange problem that i keep on running into is that sometimes it...
41
by: Twayne | last post by:
Hi, How would I go about "forcing" a user from one page to another? I have a very simple random question/answer entrance requirement for an e-mail form. After 3 page views most people are...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.