Hidden field values not accessible on server side while posting from child page to parent page using javascript

Aug 25 2008 1:11 AM

Hi

I am using asp.net 2.0 . I have 2 web pages.    parentPage.aspx  and popuppage.aspx.
I need to transfer all items of the listbox from child page to parentpage listbox. I am using a hidden field in parent page to capture the values.
Also I want to refresh the parentpage so that the parent page listbox items are available on the server side also because I need to push these values into the database.
 
 
The code below does populate the parent page listbox with values but values don't persist once the page is refreshed. I know I need to use the "__doPostBack" function of javascript but I am struggling with this. Please help me out.
 
 
ParentPage.aspx
--------------------------
<script type="text/javascript">
function
OpenPopup()
{
window.open('popuppage.aspx','childpage','width=350,height=350,scrollbars=yes');
}
function SetFruitsIntoListBox(hdnField)
{
var fruitsbox = document.getElementById('lstFruits');
var temp = new Array();
var finalarray = new Array();
temp = hdnField.split(',');
for(var i=0;i<temp.length;i++)
{
finalarray=temp[i].split(':');
var newOption = new Option();
newOption.text = finalarray[0];
newOption.value = finalarray[1];
fruitsbox.options[i]=newOption;
}
}
</script>

<asp:Panel ID="panel1" runat="server">
<asp:ListBox ID="lstFruits" runat="server" SelectionMode="Multiple">
</asp:ListBox>
<asp:HiddenField ID="hdnField" runat="server" />
<br />
<asp:Button ID="btn2" runat="server" Text="OpenListBox1PopUp1" OnClientClick="OpenPopup()" />
<asp:panel>
 
 
popuppage.aspx
 --------------------
<script type="text/javascript">
 
function TransferChildValuesToParentPage()
{
var arr = new Array();
var lbox = document.getElementById('<%= lstBox.ClientID %>');
var hidden = window.opener.document.getElementById('hdnField');
hidden="";
for(var i=0;i<lbox.length;i++)
{
hidden += lbox.options[i].text+':';
hidden += lbox.options[i].value+',';
}
window.opener.SetFruitsIntoListBox(hidden);
window.close();
}
</script>


<form id="form1"  runat="server">
<div>
<asp:ListBox ID="lstBox" runat="server" SelectionMode="Multiple">
<asp:ListItem Value="1">Oranges</asp:ListItem>
<asp:ListItem Value="2">Apples</asp:ListItem>
<asp:ListItem Value="3">Pineapples</asp:ListItem>
</asp:ListBox>
<br />
<input type="button" id="btnTransfer" value="TransferChildValuesToParentPage" onclick="TransferChildValuesToParentPage()" />


Please let me know how to make the hidden field values persist on the server side of parent page also so that they are available for further processing.
thanks & regards
casukhela krishna

 

[email protected]

 


Answers (6)