When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sections:
Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
XML Info
Information:
Feedback
Author an Article
Technology Jobs
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Print this page.
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
  • Software Developer / Programmer - Distributed Systems (NYC)
    Next Step Systems
    US-NY-New York

    Justtechjobs.com Post A Job | Post A Resume


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