Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 8th, 2007, 08:16 AM
Authorized User
 
Join Date: Sep 2003
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing & retrieving variables tto another script

I am using a template to show a picture and populate the data-fields depending on the input.
But I want to make the call to an include file or the like so I don't repeat the script in over 1000 pages but I Cannot get it to work

I need to pass two variables across to the asp script which I have set up in the Template like so:

<%
Dim tblSearch ' The table I am querying for the result
Dim strSearch ' The number in a specific field I am looking for

'These are inputs for each call to be passed from the template
<% tblSearch ="" %> 'Maximum of 6 alpha chars
<% strSearch ="" %> 'Maximum of 5 digit number
tblSearch =trim(tblSearch)
strSearch =trim(strSearch)
strSearch =UPPR(strSearch
%>

I then want to pass tblSearch and strSearch to Myscript.asp and return the record number and retrieve the result to response.write to the calling script.

Any help would be most welcome most welcome

Thank You

Roy...

 
Old October 8th, 2007, 08:50 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Just include your file in the page and then make a call to the function or method directly in your code:

MethodFromMyIncludeFile <some value>

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Beginning Visual C# 2008
Professional Search Engine Optimization with ASP.NET
Professional IIS 7 and ASP.NET Integrated Programming
Wrox Blox: Introduction to Google Gears
Wrox Blox: Create Amazing Custom User Interfaces with WPF and .NET 3.0
================================================== =========
 
Old October 9th, 2007, 01:57 AM
Authorized User
 
Join Date: Oct 2007
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There are a few ways to pass data between pages.

1) You can use Session variables.

In page1.asp set the variable...

Code:
Dim tblSearch: tblSearch = "MyTable"
Session("tblSearch") = tblSearch
In page2.asp read the variable...

Code:
Dim tblSearch: tblSearch = Session("tblSearch")
2) You can pass the data in the Querystring (appended to the URL)

In page1.asp redirect the user...

Code:
Dim tblSearch: tblSearch = "MyTable"
Response.Redirect("page2.asp?tblSearch=" & Server.URLEncode(tblSearch))
In page2.asp read the query string variable

Code:
Dim tblSearch: tblSearch = Request.Querystring("tblSearch")
3) You can store the data in hidden form fields, the user then submits those values along with the form when he presses a submit button.

In page1.asp do this...

Code:
<%
Dim tblSearch: tblSearch = "MyTable"
%>
<form name="frm1" action="page2.asp" method="post"> 
<input type="hidden" name="tblSearch" value="<%=tblSearch%>">
<input type="submit" name=submit1 value="Submit">
</form>
In page2.asp do this...

Code:
Dim tblSearch: tblSearch = Request.Form("tblSearch")

Hope that helps.


-Charles Forsyth

 
Old October 10th, 2007, 10:57 AM
Authorized User
 
Join Date: Sep 2003
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you both for the suggestions, I decided to got with the
Response.Redirect as I thought I could grasp that concept best

However I have run into a problem
I am passing it thus

Response.Redirect("findbus.asp?tblSearch=" & Server.URLEncode(tblSearch) & "?strSearch=" & Server.URLEncode(strSearch))

but there is something wrong with the second half of my statement
assuming I pass A & B The Response.write of the two shows

A?strSearch=B

So a fix for my syntax would be great please

Thanks

Roy..

 
Old October 11th, 2007, 12:36 AM
Authorized User
 
Join Date: Oct 2007
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry about that. The addition of another name/value pair to the querystring requires the use of the ampersand (&) not another question mark (?).

So you would want your resulting query string to look like this...

Code:
Response.Redirect("findbus.asp?tblSearch=" & Server.URLEncode(tblSearch) & "&strSearch=" & Server.URLEncode(strSearch))
That should do it for you. :)

Note that each additional name/value pair that you add to your querystring will require an ampersand (&) to separate them. Only the first one requires a question mark (?).

Hope that makes sense. :)

 
Old October 11th, 2007, 05:07 AM
Authorized User
 
Join Date: Sep 2003
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you again,

I cannot believe it was that close to being correct...

Now for the last bit.
I am finding the record I want with this code:
<%
Dim strDBPath
Dim strSQL
Dim strSearch
Dim tblSearch
Dim recFound
tblSearch = Request.Querystring("tblSearch")
strSearch = Request.Querystring("strSearch")
   Set cnnSearch = Server.CreateObject("ADODB.Connection")
   sPath = Server.MapPath("../buses.mdb")
   cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & sPath
   strSQL = "SELECT * FROM " & tblSearch & " WHERE fleet Like '" & Replace(strSearch, "'", "''") & "' " & "ORDER BY fleet;"
   Set rstSearch = cnnSearch.Execute(strSQL)

tblSearch = left(tblSearch,2)
tblsearch=UCASE(tblSearch)
Recfound = RSTSearch.Fields("ID")
%>

All I now need to do is pass that record back to prog1.asp and write it to a table on screen, along with a picture
Again I have wandered into this brick wall (sigh)
How to pass it and retrieve it from prog1.

so one last time please

Thank You
Roy...







Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieving and then passing XML file catbollu C# 2005 1 August 20th, 2007 01:07 PM
Passing variables karlirvin PHP How-To 4 December 2nd, 2005 08:02 PM
Inserting & Retrieving Images on Sql Server adamusufi SQL Server 2000 6 June 26th, 2005 03:32 PM
Sending & Retrieving Picture From Oracle To VB tutul128 Pro VB Databases 1 October 31st, 2004 06:41 AM
Passing variables acko ASP.NET 1.x and 2.0 Application Design 1 December 23rd, 2003 09:40 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.