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 behind for "Page 1"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 "page2"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:'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


Reply With Quote

Bookmarks