CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2011
    Posts
    2

    Retrieving Session Variable client side.

    Currently, in my web application I have a listbox that gets populated client side (via java script) with a set of ids -- we'll call this page 1. Server side, I am populating a variable with the ids and passing it through a query string to another page -- we'll call it page 2. Now, I have a previous button on page2 which allows me to go to page 1. I'm trying to figure out how to repopulate the listbox on page 1 with the values previously selected. I was thinking of just storing the set of ids in a session variable and using it client side to repopulate the list box. Can anyone advise on how to access a session variable client side?

    Here's some snippets of my code...
    - ASP page
    Code:
    // function that calls the function that populates the listbox
    function CopyItem(plyrDuplicate) {
        var plyrDuplicate = (typeof plyrDuplicate == "undefined")?'defaultValue':plyrDuplicate;
        var firstListBox = document.getElementById('<%= lstPlayerSelect.ClientID %>');
        var secondListBox = document.getElementById('<%= lstPlayerQueue.ClientID %>'); 
        for (var i = 0; i < firstListBox.options.length; i++) 
            { 
            if (firstListBox.options[i].selected) {
                var newOption = document.createElement("option");
                newOption.text = firstListBox.options[i].text;
                newOption.value = firstListBox.options[i].value;
                playerVal = newOption.value;
                CheckDuplicate(playerVal);
                var printRec =  CheckDuplicate(playerVal);
               // alert(playerVal);
               //alert(CheckDuplicate(playerVal));
                if (printRec != true) {
                secondListBox.options[secondListBox.options.length] = newOption;
                }
            }         
        }
        if (document.getElementById('ErrorMsg').style.display = 'inherit') {
            document.getElementById('ErrorMsg').style.display = 'none';
        }
        Updatelist();
        return false;
    }
    
    //Function that actually populates the listbox
    function Updatelist() 
    {
        var objPlyrQue = document.getElementById('<%= lstPlayerQueue.ClientID %>');
        var objHidden  = document.getElementById('<%= hdnPlyrLst.ClientID %>');
        objHidden.value = "";
        
        var listLength = objPlyrQue.options.length;
        for (var i = 0; i < listLength; i++) 
        {
          objHidden.value = objHidden.value + objPlyrQue.options[i].value;
          if (i != listLength-1) 
          {
           objHidden.value = objHidden.value + ', ';
          }
         //alert(objHidden.value);
        }
    }
    -- code behind for "Page 1"
    Code:
    'Builds and passes Query String 
        Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click
    
            Dim iFileType As String
            Dim iSeason As Integer
            Dim TeamStats As String
            Dim PlayerID As String
            Dim FileTypeTxt As String
            Dim iSeasonID As Integer
    
            PlayerID = hdnPlyrLst.Value
            iSeason = Request.QueryString("pSeason")
            iSeasonID = Request.QueryString("pSeasonID")
            TeamStats = Request.QueryString("pTeamStats")
            iFileType = Request.QueryString("pFileType")
            FileTypeTxt = Request.QueryString("pFileTypeTxt")
    
            Response.Redirect("send_file.aspx?pPlayerID=" & PlayerID & "&pSeasonID=" & iSeasonID & "&pSeason=" & iSeason & "&pTeamStats=" & TeamStats & "&pFileType=" & iFileType & "&pFileTypeTxt=" & FileTypeTxt)
    
        End Sub
    -- code behind for "page2"
    Code:
    'Code behind for previous buton
        Protected Sub btnPrevious_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
            'Declare Variable
            Dim pPlayerId As String
            Dim PlayerID As String
    
            'Initialize Variables
            PlayerID = Request.QueryString("pPlayerID")
            pPlayerId = String.Concat("", PlayerID, "")
    
            'If pPlayerId <> "" Then
            Session("playerId") = pPlayerId
            Response.Redirect(prevPage)
            'Else
            'Response.Redirect("prevPage?pPlayerID=" & pPlayerId)
            'End If
        End Sub

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Retrieving Session Variable client side.

    Session("variable") is a server side object, you can pass the data within from the server to the client in several different ways but I'm not sure that is what you are really looking to do.?
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Jun 2011
    Posts
    2

    Re: Retrieving Session Variable client side.

    I'm trying to retrieve the values originally stored in hdnPlyrLst.Value when I return to "page1". So, i initially populate hdnPlyrLst.Value, go to "page2", then I return back to "page1". Well, i'd like to retrieve the original values of hdnPlyrLst.Value when I return to "page1".

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Retrieving Session Variable client side.

    If those are the values you are passing to page 2 you could just pass them back again or pass them up to the server when you leave the page and back when the page reloads. Or you could store them on the client side if the client machine allows it.
    Always use [code][/code] tags when posting code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured