Can ADO Recordsets Created By ASP Be Used By JavaScript?

E

Eric Robinson

Hello,

My ASP code creates an ADO recordset object on the server.

Later on the same page, I have a javascript code snippet that I use to
dynamically populate a drop-down box based on choices made in another
drop-down box. Can this javascript (or a server-side equivalent) access the
recordset object?

--Eric
 
B

Bob Barrows [MVP]

Eric said:
Hello,

My ASP code creates an ADO recordset object on the server.

Later on the same page, I have a javascript code snippet that I use to
dynamically populate a drop-down box based on choices made in another
drop-down box. Can this javascript (or a server-side equivalent)
access the recordset object?
Only if it is passed to the client-side code. I tend to avoid trying to use
ADO on the client, preferring to use XML, but here's one way to do it (this
example uses vbscript in the client-side script but it can easily be
rewritten to use jscript instead):

http://www.davidpenton.com/testsite/tips/xml.recordset.server2client.asp

Bob Barrows
 
E

Eric Robinson

Hi,

My question was confusing because I myself am a little confused. I am not
using ADO on the client. The ADO connection and recordset are instantiated
on the server through ASP. My question is, can a server-side Javascript use
a server-side object that was created earlier on the same page by ASP code?
Or does the server-side Javascript have to instantiate its own separate
connection and recordset objects?

--Eric
 
T

Tim Slattery

Eric Robinson said:
My question was confusing because I myself am a little confused. I am not
using ADO on the client. The ADO connection and recordset are instantiated
on the server through ASP. My question is, can a server-side Javascript use
a server-side object that was created earlier on the same page by ASP code?
Or does the server-side Javascript have to instantiate its own separate
connection and recordset objects?

By the time client-side Javascript runs, all ASP code - whether
VBScript, Javascript, or another language - has finished and no longer
exists. That being the case, there's no way client-side Javascript can
use any ASP object.
 
H

Hal Rosser

Eric Robinson said:
Hello,

My ASP code creates an ADO recordset object on the server.

Later on the same page, I have a javascript code snippet that I use to
dynamically populate a drop-down box based on choices made in another
drop-down box. Can this javascript (or a server-side equivalent) access the
recordset object?
in short - No - (but)
but in a disconnected way, -
that is, you can use ASP to create javascript arrays to hold the data which
javascript can then use -
howsomever - keep in mind that the javascript code won't be able to access
the database.
remember - once the user has received the page - its on his computer, and
not the server.
The user's browser is rendering a page which is the 'result' - or output
from an ASP script.
Javascript executes in the user's browser.
 
E

Eric Robinson

Forgive me for belaboring the issue, but you said:

"By the time client-side Javascript runs, all ASP code -
whether VBScript, Javascript, or another language - has finished..."

I understand that, but my real question is in reference to all SERVER-side
code.

Is it possible for JavaScript code running on the server to call methods in
objects instantiated by ASP code running on the server?
 
E

Eric Robinson

I'm probably goping about this all wrong and making it too hard. The
situation is pretty basic. In ASP I create two server-side recordsets, which
I'll call rsCircuses and rsClowns.

The records in rsCircuses look like this:

ID CircusName
1 Ringling Brothers
2 Barnum and Bailey
3 Circus Circus
4 Cirque du Soliel
5 etc.

The records in rsClowns look like this:

ID ClownName CircusID
1 Bozo 2
2 Dopey 4
3 Bingo 2
4 Poo Poo 3
5 etc.

rsCircuses is used to populate a drop-down menu. When the user chooses a
circus from the menu, I want to populate the second drop-down with records
picked from rsClowns based on the CircusID.

I was able to populate the first drop-down from rsCircuses, but I cannot
figure a way to populate the second drop-down based on a database query.
 
E

Eric Robinson

I think I got it.

I did everything on the server with ASP, but in the ASP code I actually
wrote out a client-side JavaScript, like this:

<%
Response.Write "<script language=""javascript"">"
Response.Write (... the javascript drop-down box code...)
Response.Write "</script>"
%>

It may be yoogly but it seems to work.
 
B

Bob Barrows [MVP]

Eric said:
I'm probably goping about this all wrong and making it too hard. The
situation is pretty basic. In ASP I create two server-side
recordsets, which I'll call rsCircuses and rsClowns.

The records in rsCircuses look like this:

ID CircusName
1 Ringling Brothers
2 Barnum and Bailey
3 Circus Circus
4 Cirque du Soliel
5 etc.

The records in rsClowns look like this:

ID ClownName CircusID
1 Bozo 2
2 Dopey 4
3 Bingo 2
4 Poo Poo 3
5 etc.

rsCircuses is used to populate a drop-down menu. When the user
chooses a circus from the menu, I want to populate the second
drop-down with records picked from rsClowns based on the CircusID.

This i where client-side code is required (unless you want to submit back to
the server when the user picks a circus). Only client-side code can respond
to user events without involving a submission to a server page.

My preferred technique is to pass an xml document containing the clowns data
to the client-side jscript code, either via a data island (IE-only; see
http://www.davidpenton.com/testsite/tips/xml.data.islands.asp) or by
response.writing a string containing the xml into a variable in a clientside
code block which is the techniques used in this example:
http://www.davidpenton.com/testsite/tips/xml.recordset.server2client.asp


Youcan also use the xmlhttprequest object to request data from server pages
without submitting your form. This technique is illustrated in the dynamic
listbox demo which can be downloaded from here:
http://www.thrasherwebdesign.com/index.asp?pi=links&hp=links.asp&c=&a=clear

For further questions about the client-side code, you need to post to a
relevant newsgroup. I suggest m.p.scripting.jscript.

Bob Barrows
 
R

Roland Hall

:I think I got it.
:
: I did everything on the server with ASP, but in the ASP code I actually
: wrote out a client-side JavaScript, like this:
:
: <%
: Response.Write "<script language=""javascript"">"
: Response.Write (... the javascript drop-down box code...)
: Response.Write "</script>"
: %>
:
: It may be yoogly but it seems to work.

I'm not sure what yoogly is but there is no ASP vs javascript code. Replace
ASP with VBScript.
And, in your client-side script block, use <script type="text/javascript">
language= is deprecated on the client-side.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
B

Bob Lehmann

Is it possible for JavaScript code running on the server to call methods
in objects instantiated by ASP code running on the server?

What's the difference between "JavaScript code running on the server " and
ASP code? Isn't code running on the server already ASP code?

Bob Lehmann

Eric Robinson said:
Forgive me for belaboring the issue, but you said:

"By the time client-side Javascript runs, all ASP code -
whether VBScript, Javascript, or another language - has finished..."

I understand that, but my real question is in reference to all SERVER-side
code.

Is it possible for JavaScript code running on the server to call methods in
objects instantiated by ASP code running on the server?
 
E

Eric Robinson

I have been saying "ASP" when I often meant server-side Never having written
anything in Jscript, I had Vbscript and ASP tied together in my mind.
Vbscript. Sorry about that. Anyway, the problem is solved. Thanks for all
the feedback.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top