Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing array from client to server

Status
Not open for further replies.

guyute

MIS
Nov 2, 2001
8
0
0
US
I need to pass an array from client to server when the window is closed. I have everything but how to pass the array down. Can anyone help on this?

Thanks
 
Where is the array - javascript? You can use the onUnload to post the array like a form...

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
I am creating the array server side based off of a DataRow. The array is getting passed to the client when the page loads and is formatted into a javascript Array() which fills a table based form. To eliminate the need for a ton of postbacks I am letting the user make changes to the table which in turn updates the array before refilling the table with new values.

I catch the onBeforeUnload event to pass the array back to the server when the page is closing but that is where I ran into a snag. As far as I know passing an array from client to server is much more work than from server to client.

I believe after scouring the net that the easiest way is the method posted here:
In order to avoid global variables and functions on both client and server side I rewrote the code into both javascript and vb classes.

Thanks for your help though

Jim
 
It depends on how the array is formatted. For instance if you know that the array has 10 fields and the first is name, the second is age and so forth you could do something like this...

function pageUnload(){
document.hiddenForm.myField.value = myFormArray.join("@#@#") //or some other obscure separator
document.hiddenForm.action = "formHandler.asp"
document.hiddenForm.method = "post"
document.hiddenForm.submit()
}


then on the form handler you just reform the array

dim formArr
formArr = split(request("myField"), "@#@#")

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Yes, the size and order of the array is static for this purpose at least. The method I found does a little bit more in the way of error checking and has more potential for customization but for the one instance I need to use this for your method is WAY easier and Faster. I had no idea there was a join and split method or what it did.

Thanks man, you saved me a bundle of time.

Jim
 
Perhaps keep something like a copy of the array with each part separated with a | or something in a hidden field.

And at the same time the user changes the JavaScript array you also would change the hidden field.

And then the hidden field could be available on whatever page it is posted to (if that's a viable approach). Just my $0.02 worth.

Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top