By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,515 Members | 1,178 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,515 IT Pros & Developers. It's quick & easy.

pass array object of child window references from client side to server side

zybernau
P: 35
hi,

here is my scenario
i am having a array variable in javascript which contains data.
while refreshing or postback these varibles got lost and i did'nt able to get those data in the variables after a refresh/postback

please give me idea how to store back these variable to server before rereshing and taking them back on load


note: i am using asp.net as server side
Thanks,

Raj
Nov 1 '07 #1
Share this Question
Share on Google+
18 Replies


dmjpro
100+
P: 2,476
hi,

here is my scenario
i am having a array variable in javascript which contains data.
while refreshing or postback these varibles got lost and i did'nt able to get those data in the variables after a refresh/postback

please give me idea how to store back these variable to server before rereshing and taking them back on load


note: i am using asp.net as server side
Thanks,

Raj
you can do it using Cookie ...... but the problem is you can't store Array in Cookie ..... you have to store it as String

Debasis Jana
Nov 1 '07 #2

zybernau
P: 35
you can do it using Cookie ...... but the problem is you can't store Array in Cookie ..... you have to store it as String

Debasis Jana

Thanks JANA ,

but what i am trying is
while onload and onunload the array array object is stored in hdnfield
and on load, its got restored in the javascript
...
window.onload = setChilds("htmHdnChild");

...
<body onunload = "getChilds('htmHdnChild')">


function setChilds(HdnID)
{
alert("in set child");
var hdnCtrl = document.all(HdnID);
if (hdnCtrl!=null)
{
myChild = hdnCtrl;
alert(myChild.length);
}
}

function getChilds(HdnID)
{
//alert("in Get child");
var hdnCtrl = document.all(HdnID);
alert(myChild.length);
hdnCtrl.value = myChild;
alert(hdnCtrl);
}

while setting the array object for the hidden field, its not working for me is there there any other way

Thanks
Nov 1 '07 #3

zybernau
P: 35
but what i am trying is
while onload and onunload the array array object is stored in hdnfield
and on load, its got restored in the javascript
...
Expand|Select|Wrap|Line Numbers
  1. window.onload = setChilds("htmHdnChild");
...
[HTML]<body onunload = "getChilds('htmHdnChild')">[/HTML]


Expand|Select|Wrap|Line Numbers
  1. function setChilds(HdnID)
  2. {
  3. alert("in set child");
  4. var hdnCtrl = document.all(HdnID);
  5. if (hdnCtrl!=null)
  6. {
  7. myChild = hdnCtrl;
  8. alert(myChild.length);
  9. }
  10. }
  11.  
  12. function getChilds(HdnID)
  13. {
  14. //alert("in Get child");
  15. var hdnCtrl = document.all(HdnID);
  16. alert(myChild.length);
  17. hdnCtrl.value = myChild;
  18. alert(hdnCtrl);
  19. }
  20.  
while setting the array object for the hidden field, its not working for me is there there any other way
Nov 1 '07 #4

dmjpro
100+
P: 2,476
Thanks JANA ,

but what i am trying is
while onload and onunload the array array object is stored in hdnfield
and on load, its got restored in the javascript
...
window.onload = setChilds("htmHdnChild");

...
<body onunload = "getChilds('htmHdnChild')">


function setChilds(HdnID)
{
alert("in set child");
var hdnCtrl = document.all(HdnID);
if (hdnCtrl!=null)
{
myChild = hdnCtrl;
alert(myChild.length);
}
}

function getChilds(HdnID)
{
//alert("in Get child");
var hdnCtrl = document.all(HdnID);
alert(myChild.length);
hdnCtrl.value = myChild;
alert(hdnCtrl);
}

while setting the array object for the hidden field, its not working for me is there there any other way

Thanks
How can you assign an array to a hidden field?
It is not possible.
You can store the values in a hidden field something like this.

Expand|Select|Wrap|Line Numbers
  1. <input type="hidden" id = "hdnID">
  2.  
Expand|Select|Wrap|Line Numbers
  1. var hdn = document.getElementById('hdnID');
  2. var array_values = "";
  3. var separator = "/*the separator character so that it does not occur in your array values*/";
  4. var array_obj = /*this is your array object*/ ;
  5. for(var i = 0;i<array_obj.length-1;i++) array_values += array_obj[i] + separator;
  6. array_values += array_obj[i];
  7. /*now write a code for retrieving the values from your hidden field ...using String.split method*/
  8.  
Debasis
Nov 1 '07 #5

dmjpro
100+
P: 2,476
but what i am trying is
while onload and onunload the array array object is stored in hdnfield
and on load, its got restored in the javascript
...
window.onload = setChilds("htmHdnChild");

...
<body onunload = "getChilds('htmHdnChild')">


function setChilds(HdnID)
{
alert("in set child");
var hdnCtrl = document.all(HdnID);
if (hdnCtrl!=null)
{
myChild = hdnCtrl;
alert(myChild.length);
}
}

function getChilds(HdnID)
{
//alert("in Get child");
var hdnCtrl = document.all(HdnID);
alert(myChild.length);
hdnCtrl.value = myChild;
alert(hdnCtrl);
}

while setting the array object for the hidden field, its not working for me is there there any other way
Don't do post double and try to use code tags before post.

debasis
Nov 1 '07 #6

zybernau
P: 35
How can you assign an array to a hidden field?
It is not possible.
You can store the values in a hidden field something like this.

Expand|Select|Wrap|Line Numbers
  1. <input type="hidden" id = "hdnID">
  2.  
Expand|Select|Wrap|Line Numbers
  1. var hdn = document.getElementById('hdnID');
  2. var array_values = "";
  3. var separator = "/*the separator character so that it does not occur in your array values*/";
  4. var array_obj = /*this is your array object*/ ;
  5. for(var i = 0;i<array_obj.length-1;i++) array_values += array_obj[i] + separator;
  6. array_values += array_obj[i];
  7. /*now write a code for retrieving the values from your hidden field ...using String.split method*/
  8.  
Debasis


Thanks Debasis,

is there any replacement for the hidden field that can store array variable
in server
Nov 1 '07 #7

dmjpro
100+
P: 2,476
Thanks Debasis,

is there any replacement for the hidden field that can store array variable
in server
hey are you looking for server side script ...?
but you have first send it to ..... server ............then you can store it.
i think you can't directly send an array to server.

debasis
Nov 1 '07 #8

zybernau
P: 35
hey are you looking for server side script ...?
but you have first send it to ..... server ............then you can store it.
i think you can't directly send an array to server.

debasis
that is what i am asking man, what we will do for text, we will store in the a hidden field and read the same in the server side, store in a session variable and retrive the same in some where in other pages or the same postback page

here what i need to know is there any thing replacement for hidden field
to store array objects..


Thanks
Nov 1 '07 #9

acoder
Expert Mod 15k+
P: 16,027
Threads merged. Please do not double post.
Nov 1 '07 #10

zybernau
P: 35
Dear All,

i am having a parent window
say parent.aspx
here i am creating child windows in javascript
like this
Expand|Select|Wrap|Line Numbers
  1. var myChild = new Array();
  2.  
  3. function MenuPopUp(url,width,height,left,top)
  4.     {
  5.         if (width == 0)//code to close all the open windows
  6.         {
  7.  
  8.             var len=0;
  9.             for (i=0; i<myChild.length; i++) 
  10.                 {
  11.                 if (myChild[i].closed == false)
  12.                     len = len+1;
  13.                     //alert(myChild[i])
  14.                 }
  15.             //alert(len);
  16.  
  17.             if (len >0) {
  18.  
  19.             if (len == 1)
  20.             {
  21.                 alert(" Switch from Company - Closing the open Window ")    ;
  22.             }
  23.             else
  24.             {
  25.                 alert(" Switch from Company - Closing all "+ len +" open Windows ")    ;
  26.             }
  27.  
  28.             for (i=0; i<len; i++) 
  29.                 {
  30.                 if (myChild[i].closed == false)
  31.                 myChild[i].close();
  32.                 }
  33.             }
  34.             relocate(url,"s_company_name");
  35.  
  36.         }
  37.         else// code open newe window and assign to the array 
  38.         {
  39.             var Children ;
  40.             Children = myChild.length;
  41.             //alert(Children);
  42.             myChild[Children] = window.open(url,"","width=" + width +",height=" + height +",top=" + top + ",left=" + left + ",toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no");
  43.         }
  44.     }
  45.  
this function will open a new window in else part and closes the existing windows in the if part

and for each window i am opening i am referencing/assigning it[window] to a array object

so while doing some action in the main page , i need to close the child windows , so i can directly close by looping though the array and close the windows.

but in my main page [parent] page i have implemented a page refreshing logic
according to this the page will refresh after 500 secs

so in this following scenario the certain open windows become orphan
1) opening 2 new windows at 10th sec
2) wait until the page refreshes [say 500]
3) after 500 sec open another window
4) now do the task where you need to close all the child windows
5) the already opened 2 windows left open as orphans

this is why because while refreshing the javascript variable [myChild] is being reset and all the values contained in the variable is destroyed.

the windows opened will have no reference

Question:
so now i need to pass this array object to server[on unload event] and save the object in the session variable and retrive and restoring it to the array variable while the page loads again
so i may be having reference to all the child windows opened..

please give me solution

Thanks,
Raj
Nov 2 '07 #11

gits
Expert Mod 5K+
P: 5,390
hi ...

i think that will not work the way you think, i'm quite sure that you cannot store window-references at the server since that are client-side objects ... but you have other possibilities:

1. instead of refreshing the entire page you may use an ajax-call and update only the relevant parts of your page

2. use a frameset with a frame for your main page and one with 0px height and width, where you may store your references during the app-runtime

kind regards
Nov 2 '07 #12

acoder
Expert Mod 15k+
P: 16,027
but what i am trying is
while onload and onunload the array array object is stored in hdnfield
and on load, its got restored in the javascript
...
[snip]
while setting the array object for the hidden field, its not working for me is there there any other way
Use the Array object's join() method.
Nov 2 '07 #13

zybernau
P: 35
hi ...

i think that will not work the way you think, i'm quite sure that you cannot store window-references at the server since that are client-side objects ... but you have other possibilities:

1. instead of refreshing the entire page you may use an ajax-call and update only the relevant parts of your page

2. use a frameset with a frame for your main page and one with 0px height and width, where you may store your references during the app-runtime

kind regards

Thanks gits,
so there is no way for passing the array objects from client side to server side
Nov 2 '07 #14

zybernau
P: 35
Use the Array object's join() method.


please see this
link ...
Nov 2 '07 #15

acoder
Expert Mod 15k+
P: 16,027
Since the threads are dealing with the same problem, I've merged the threads.
Nov 2 '07 #16

acoder
Expert Mod 15k+
P: 16,027
Thanks gits,
so there is no way for passing the array objects from client side to server side
Normal arrays with simple data such as numbers and strings, yes, but references to child windows, no.

Why not use Ajax, frames or iframes as gits has suggested?
Nov 2 '07 #17

zybernau
P: 35
Normal arrays with simple data such as numbers and strings, yes, but references to child windows, no.

Why not use Ajax, frames or iframes as gits has suggested?
Thanks moderator

i don't know ajax or sorta please refer me some posts, so that i can start with .. Thanks
Nov 3 '07 #18

acoder
Expert Mod 15k+
P: 16,027
See this example and also check out the tutorials in the Offsite Links thread.
Nov 3 '07 #19

Post your reply

Sign in to post your reply or Sign up for a free account.