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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zybernau
    New Member
    • Mar 2007
    • 34

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

    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
    Top Contributor
    • Jan 2007
    • 2476

    #2
    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

    Comment

    • zybernau
      New Member
      • Mar 2007
      • 34

      #3
      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("htmH dnChild");

      ...
      <body onunload = "getChilds('htm HdnChild')">


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

      function getChilds(HdnID )
      {
      //alert("in Get child");
      var hdnCtrl = document.all(Hd nID);
      alert(myChild.l ength);
      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

      Comment

      • zybernau
        New Member
        • Mar 2007
        • 34

        #4
        set array object to hidden field

        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
        ...
        Code:
        window.onload = setChilds("htmHdnChild");
        ...
        [HTML]<body onunload = "getChilds('htm HdnChild')">[/HTML]


        [CODE=javascript]function setChilds(HdnID )
        {
        alert("in set child");
        var hdnCtrl = document.all(Hd nID);
        if (hdnCtrl!=null)
        {
        myChild = hdnCtrl;
        alert(myChild.l ength);
        }
        }

        function getChilds(HdnID )
        {
        //alert("in Get child");
        var hdnCtrl = document.all(Hd nID);
        alert(myChild.l ength);
        hdnCtrl.value = myChild;
        alert(hdnCtrl);
        }
        [/CODE]
        while setting the array object for the hidden field, its not working for me is there there any other way
        Last edited by acoder; Nov 1 '07, 08:36 AM. Reason: Added code tags

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          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("htmH dnChild");

          ...
          <body onunload = "getChilds('htm HdnChild')">


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

          function getChilds(HdnID )
          {
          //alert("in Get child");
          var hdnCtrl = document.all(Hd nID);
          alert(myChild.l ength);
          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.

          [code=html]
          <input type="hidden" id = "hdnID">
          [/code]

          [code=javascript]
          var hdn = document.getEle mentById('hdnID ');
          var array_values = "";
          var separator = "/*the separator character so that it does not occur in your array values*/";
          var array_obj = /*this is your array object*/ ;
          for(var i = 0;i<array_obj.l ength-1;i++) array_values += array_obj[i] + separator;
          array_values += array_obj[i];
          /*now write a code for retrieving the values from your hidden field ...using String.split method*/
          [/code]

          Debasis

          Comment

          • dmjpro
            Top Contributor
            • Jan 2007
            • 2476

            #6
            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("htmH dnChild");

            ...
            <body onunload = "getChilds('htm HdnChild')">


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

            function getChilds(HdnID )
            {
            //alert("in Get child");
            var hdnCtrl = document.all(Hd nID);
            alert(myChild.l ength);
            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

            Comment

            • zybernau
              New Member
              • Mar 2007
              • 34

              #7
              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.

              [code=html]
              <input type="hidden" id = "hdnID">
              [/code]

              [code=javascript]
              var hdn = document.getEle mentById('hdnID ');
              var array_values = "";
              var separator = "/*the separator character so that it does not occur in your array values*/";
              var array_obj = /*this is your array object*/ ;
              for(var i = 0;i<array_obj.l ength-1;i++) array_values += array_obj[i] + separator;
              array_values += array_obj[i];
              /*now write a code for retrieving the values from your hidden field ...using String.split method*/
              [/code]

              Debasis


              Thanks Debasis,

              is there any replacement for the hidden field that can store array variable
              in server

              Comment

              • dmjpro
                Top Contributor
                • Jan 2007
                • 2476

                #8
                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 ............the n you can store it.
                i think you can't directly send an array to server.

                debasis

                Comment

                • zybernau
                  New Member
                  • Mar 2007
                  • 34

                  #9
                  Originally posted by dmjpro
                  hey are you looking for server side script ...?
                  but you have first send it to ..... server ............the n 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

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    Threads merged. Please do not double post.

                    Comment

                    • zybernau
                      New Member
                      • Mar 2007
                      • 34

                      #11
                      Client Windows!!!

                      Dear All,

                      i am having a parent window
                      say parent.aspx
                      here i am creating child windows in javascript
                      like this
                      Code:
                      var myChild = new Array();
                      
                      function MenuPopUp(url,width,height,left,top)
                      	{
                      		if (width == 0)//code to close all the open windows
                      		{
                      			
                      			var len=0;
                      			for (i=0; i<myChild.length; i++) 
                      				{
                      				if (myChild[i].closed == false)
                      					len = len+1;
                      					//alert(myChild[i])
                      				}
                      			//alert(len);
                      			
                      			if (len >0) {
                      			
                      			if (len == 1)
                      			{
                      				alert(" Switch from Company - Closing the open Window ")	;
                      			}
                      			else
                      			{
                      				alert(" Switch from Company - Closing all "+ len +" open Windows ")	;
                      			}
                      			
                      			for (i=0; i<len; i++) 
                      				{
                      				if (myChild[i].closed == false)
                      				myChild[i].close();
                      				}
                      			}
                      			relocate(url,"s_company_name");
                      			
                      		}
                      		else// code open newe window and assign to the array 
                      		{
                      			var Children ;
                      			Children = myChild.length;
                      			//alert(Children);
                      			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");
                      		}
                      	}
                      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

                      Comment

                      • gits
                        Recognized Expert Moderator Expert
                        • May 2007
                        • 5388

                        #12
                        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

                        Comment

                        • acoder
                          Recognized Expert MVP
                          • Nov 2006
                          • 16032

                          #13
                          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.

                          Comment

                          • zybernau
                            New Member
                            • Mar 2007
                            • 34

                            #14
                            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

                            Comment

                            • zybernau
                              New Member
                              • Mar 2007
                              • 34

                              #15
                              Originally posted by acoder
                              Use the Array object's join() method.


                              please see this
                              link ...

                              Comment

                              Working...