Link to home
Start Free TrialLog in
Avatar of klia
klia

asked on

passing recordset to another page ?

hi,

i got a recordset need to pass to my form (which is
in another page, e.g. order_list.asp), is it possible
to achieve that?

orders.asp    --- (recordset) -->   order_list.asp


in the orders.asp, i execute my sql statement. and
i need a way to pass my recordset (if can no session)

cheers,
klia
Avatar of kmv
kmv

How can you pass parameters from one script page to other.
Best way is to use server-side methods.
1. Using Session or Application objects.
2. Write your own parameter storage object and use it on both pages. Use apartment model to avoid multiply access problem.
3. Using file (write to file on one page and then read from other). But you need to solve concurrent access problem (possible use Application.Lock and Application.Unlock)

Client-side passing.
Create page with form and place recordset fields in it (possible in a hidden fields). Then user submit form to other script. It will increase traffic but on some systems it is one way to pass parameters, e.g. some payment systems.

Good luck!
Avatar of klia

ASKER

in the order.asp, i do all the asp programming,
i try to mimimize the asp coding in my order_list.asp
where in the order.asp, i have case, db select and
other programming logic, while in order_list.asp, i
want to act as 'interface' only file with mimimal
asp logic inside.
klia,

Best way using input type

sample:
<input type="hidden" name="ID" value="<%=Rs("ID")%>">

Regards,
Wee Siong
It sounds as though you simply want to use your ASP page, order.asp, like an object.  If your web application is on a Windows 2000 Server, you can use:

Server.Execute("order.asp")

This will go out and execute order.asp and return the results to the page that called it.  You can then use the recordset as though it were created within the order_list.asp page.  Additionally, any parameters, form values or query strings that are passed to order_list.asp are also accessible by order.asp.
Avatar of klia

ASKER

ok,

i try to write what i intend to, i still new in asp
coding, my previous language is php. i'm not sure
whether this method can be done using asp, but in
php, this is what i'm using, after select the record
i just include the order_list.asp and inside the
order_list.asp, i just display them. very easy.


order.asp
----------
<%
mode = request.querystring("mode") 'get the mode

select case Cstr(mode)

case "add"
    'prepre add a new record

case "edit"
    'get the data and pass to order_form.asp to edit
    strSql = "select * from orders where ordid = " & ordid
    rs.execute(strSql)
    ....
    ....

case else
    strSql = "select * from orders order by ordid"
    rs.execute(strSql)
    'i'm thinking how should i pass my rs to order_list.asp

end select
%>

order_list.asp
--------------

<html>
<body>
<%
'i know this is not asp code....

while rs.eof
   displayrecord
endwhile
%>
</body>
</html>
Using your example, Server.Execute would not work. Instead you would have to use Server.Transfer.  This would make all elements including the recordset and form and querystring collections available to order_list.asp. Example:

case else
   strSql = "select * from orders order by ordid"
   rs.execute(strSql)
   Server.Transfer("order_list.asp")
end select


PS  -  Again, this will only work on Win2000

if I get it right, you want the 1st ASP (orders) page to retrieve a recordset, building the where clause using a parameter value.

if orderlist.asp, only needs to display the recordset results, and orders can produce an standard format you could take 2 approaches,

On the client side either use frames and DHTML, or an iframe, depending on your browser target, where one frame is used to make the browser load the window.

on IE 4 and above, you can do the following:

orderlist.asp:
<HTML>
<BODY>
<FORM action='orders.asp' target='orderlistframe'>

    <input ....>
</FORM>
<IFRAME name='orderlistframe' width="100%" height="100%"></IFRAME>
</BODY>
</HTML>

the netscape example is more complex, beacuse it envolves the following concepts:
<LAYER> tag
javascript client side programing for DHML.

On the server side, you can do the following:
convert your 1st page to a function as follows:

<script runat=server>
function orderlist(parameter)
   VBScript code
end function
</script>

and on the 2nd page, include the first one

<script runat=server src="theotherpage.asp">
</script>

after that, call the function from the asp page
<% call orderlist(parameter)%>

or you can use session variables, you may load an array to a session object, avoiding to create to many of them.

About Server.Execute
http://support.microsoft.com/support/kb/articles/Q224/3/63.ASP
http://msdn.microsoft.com/library/psdk/iisref/vbob9pid.htm
About Server.Transfer
http://msdn.microsoft.com/library/psdk/iisref/vbob9waa.htm

There is other technique:
Use SSI (server side include)
Let file orders.asp have input parameters in a query string or in a post header. I.e user calls order.asp,
order_list.asp will only show results of query.
In file order.asp you prepare recordset and store it in variable with certain name, e.g. rs. You don't write text to output buffer in file order.asp (except errors etc.)

in file order_list.asp you write smth like this
<html>
<body>
<%
while rs.eof
  'here you write code which will show your recordset fields. E.g.
  Response.Write "<tr><td>Item</td><td>"&rs("ItemName")&"</td>"
  Response.Write "<td>QTY</td><td>"&rs("ItemQTY")&"</td></tr>"
'or smth like this
endwhile
%>
</body>
</html>

In file orders.asp you place next code:
<%
'code to prepare recordset
'if it prepared correctly then
%>
<!--#include virtual="order_list.asp.asp"-->

That's all!
Text of order_list.asp will be included instead of line <!--#include virtual="order_list.asp.asp"--> (if you know C/C++ it is easy to understand for you)

About "include" directive
http://msdn.microsoft.com/library/psdk/iisref/iiwainc.htm

Good Luck!
Avatar of klia

ASKER

due to design, we cannot use any frame, (NS also didn't
support iframe if i'm not wrong)

for the order.asp, it will serve as 'controller' and
will accept the mode passing by the caller, either from
order_list.asp or order_form.asp etc. and then it will
evaluate the mode and act accordingly. I try to implement
this method using asp, while previously..I've been using
this method in my php programming. and we are very happy
cos it is fast and it seperate the interface part and
the coding part.

Try #include directive
But better way to separate interface and coding part is XML/XSL
Use pasp - it helps to do it. But of course, it is possible to use simple asp.

Good luck!
#include doesn't mean frames. Read article please.
http://msdn.microsoft.com/library/psdk/iisref/iiwainc.htm

It is simplest way. But you need to carefully use names of your variables, recordsets etc.
If you write your variables names used in other file on a paper and will look at it periodically you will have less problems with them. :)

I'd like to use XML in your case. But it takes time to study.
Avatar of klia

ASKER

hi kmv,

if using XML, how the implementation like?

since I'm learning asp, why not learn it the rite way? :-)

cheers,
klia
ASKER CERTIFIED SOLUTION
Avatar of kmv
kmv

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you.
Best regards.