When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles [1.x] [2.0]
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips
Search

Sections:
Book Reviews
Sample Chapters
Commonly Asked Message Board Questions
Headlines from ASPWire.com
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
Web Hosts
XML Info
Information:
Advertise
Feedback
Author an Article
Technology Jobs



















internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Print this page.

.Net Developer
Professional Technical Resources
US-WA-Bellingham

Justtechjobs.com Post A Job | Post A Resume

Published: Tuesday, October 19, 1999

Passing Arrays from One ASP Page to Another, Part 2


In Part 1, we looked at how to create an array and encode it for passing it to another web page. In this part of the article, we are going to look at how to receive this information and decode it back into an array.

- continued -

When variables are passed from one ASP page to another, either via the querystring or a form, when multiple variables have the same name, the Request object creates a comma-delimited list containing all of the values that have the same name. For example, if you call an ASP page with the following querystring:

http://www.myserver.com/SomePage.asp?Pets=Barney&Pets=Alexis&Pets=Spud

and then print out the value of Request("Pets") in SomePage.asp, you will receive the following output:

Barney, Alexis, Spud

We can use the split function to turn this comma-delimited list into an array! If you are unfamiliar with split, be sure to read Parsing with join and split.

So, in ReceiveArray.asp, we need to begin with reading in the WeekDays variable, that was passed in via either the querystring or a form. Next, we need to create an array variable (aWeekDays), and use split to populate this array with the comma-delimited list sent from CreateArray.asp. Let's look at some code!

'Read in the WeekDays Array Dim strWeekDays strWeekDays = Request("WeekDays") 'strWeekDays is a comma-delmited list of values 'So we can split on the comma to create an array! Dim aWeekDays aWeekDays = split(strWeekDays, ",")

Isn't this neat? We've just created an array named aWeekDays in ReceiveArray.asp that is nearly identical to the aWeekDays array we created in CreateArray.asp! The only discrepency between the two is that the aWeekDays array in ReceiveArray.asp contains a space as the first character for all elements but the first. This is because the comma-delimited list represented by strWeekDays contains a space after each comma. So, to fix this, we need to iterate through the array, Trimming each element. The following code will do just that:

Dim iLoop For iLoop = LBound(aWeekDays) to UBound(aWeekDays) aWeekDays(iLoop) = Trim(aWeekDays(iLoop)) Next

Finally, we can print out the contents of the aWeekDays array if we'd like. Just need to iterate through each element in the array.

For iLoop = LBound(aWeekDays) to UBound(aWeekDays) Response.Write aWeekDays(iLoop) & "<BR>" Next

Well, that's all there is to it! I hope you learned something new! :)


Attachments:

  • Download the source for CreateArray.asp in text format
  • Download the source for ReceiveArray.asp in text format


    Windows Internet Technology | ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article



  • JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers