Connecting Tech Pros Worldwide Forums | Help | Site Map

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

zybernau's Avatar
Member
 
Join Date: Mar 2007
Location: heart of tamil
Posts: 35
#1: Nov 1 '07
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

dmjpro's Avatar
Lives Here
 
Join Date: Jan 2007
Location: India (West-Bengal)
Posts: 2,451
#2: Nov 1 '07

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


Quote:

Originally Posted by zybernau

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
zybernau's Avatar
Member
 
Join Date: Mar 2007
Location: heart of tamil
Posts: 35
#3: Nov 1 '07

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


Quote:

Originally Posted by dmjpro

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
zybernau's Avatar
Member
 
Join Date: Mar 2007
Location: heart of tamil
Posts: 35
#4: Nov 1 '07

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


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
dmjpro's Avatar
Lives Here
 
Join Date: Jan 2007
Location: India (West-Bengal)
Posts: 2,451
#5: Nov 1 '07

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


Quote:

Originally Posted by zybernau

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
dmjpro's Avatar
Lives Here
 
Join Date: Jan 2007
Location: India (West-Bengal)
Posts: 2,451
#6: Nov 1 '07

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


Quote:

Originally Posted by zybernau

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
zybernau's Avatar
Member
 
Join Date: Mar 2007
Location: heart of tamil
Posts: 35
#7: Nov 1 '07

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


Quote:

Originally Posted by dmjpro

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
dmjpro's Avatar
Lives Here
 
Join Date: Jan 2007
Location: India (West-Bengal)
Posts: 2,451
#8: Nov 1 '07

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


Quote:

Originally Posted by zybernau

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
zybernau's Avatar
Member
 
Join Date: Mar 2007
Location: heart of tamil
Posts: 35
#9: Nov 1 '07

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


Quote:

Originally Posted by dmjpro

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
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#10: Nov 1 '07

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


Threads merged. Please do not double post.
zybernau's Avatar
Member
 
Join Date: Mar 2007
Location: heart of tamil
Posts: 35
#11: Nov 2 '07

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


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
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,134
#12: Nov 2 '07

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


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
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#13: Nov 2 '07

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


Quote:

Originally Posted by zybernau

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.
zybernau's Avatar
Member
 
Join Date: Mar 2007
Location: heart of tamil
Posts: 35
#14: Nov 2 '07

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


Quote:

Originally Posted by gits

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
zybernau's Avatar
Member
 
Join Date: Mar 2007
Location: heart of tamil
Posts: 35
#15: Nov 2 '07

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


Quote:

Originally Posted by acoder

Use the Array object's join() method.



please see this
link ...
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#16: Nov 2 '07

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


Since the threads are dealing with the same problem, I've merged the threads.
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#17: Nov 2 '07

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


Quote:

Originally Posted by zybernau

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?
zybernau's Avatar
Member
 
Join Date: Mar 2007
Location: heart of tamil
Posts: 35
#18: Nov 3 '07

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


Quote:

Originally Posted by acoder

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
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#19: Nov 3 '07

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


See this example and also check out the tutorials in the Offsite Links thread.
Reply