Help with disappearing items in listbox

V

Vengeance

On the parent_form.aspx I have these controls

<asp:listbox id="Operators" runat="server" Width="163px"
SelectionMode="Multiple" Rows="2"></asp:listbox>
<INPUT class="loButton" onclick="java script:getOptionPicker('?mid=TS5
&callingcontrol=Operators');" type="button" value="+">
<asp:button id="save" runat="server" CssClass="loButton" Text="Save">
</asp:button>

I also use a global.js file which adds the following functions

function getOptionPicker(extras)
{
var features;
features = " status=no,scrollBars=no,resizable=no,toolbar=no,me
nubar=no,location=no,directories=no,width=300,heig
ht=200";
var option_window;
option_window = window.open("option_picker.aspx" + extras,
"Add_Options", features);
option_window.focus();
}

function addToParentList(sourceList, destinationList)
{
destinationList = document.getElementById(destinationList);
for(var count = destinationList.options.length - 1; count >= 0; count--)
{
destinationList.options[count] = null;
}
for(var i = 0; i < sourceList.options.length; i++)
{
if (sourceList.options != null)
{destinationList.options = new Option(sourceList.options.text,
sourceList.options.value);}
}
}



On the option_picker.aspx form I have these controls and functions

<asp:listbox id="destList" runat="server" SelectionMode="Multiple"
Width="100px" Height="134px" AutoPostBack="True"></asp:listbox>
<input id="Done" onclick="java script:addSelectedItemsToParent()"
type="button" value="Done" name="Done">

function addSelectedItemsToParent()
{
self.opener.addToParentList(window.document.forms[0].destList,
window.document.forms[0].CallingControl.value);
window.close();
}



So, when the user clicks the INPUT button on the parent_form
getOptionPicker() is called which opens the option_picker form.
From there they do what they need and get a list of items in the
destList asp:listbox and click the Done INPUT button.
This calls the local addSelectedItemsToParent() which in turn calls the
addToParentList() from the global.js file which was included on the
parent form.
The Operators asp:listbox is correctly filled with the contents from the
child form.
The user then clicks the Save asp:button to store their information.
However, by time any code can be executed in that button's click event,
the listbox reads as being empty.

I am at a total loss as to why this is happening. I have similar code
that deals with setting the value of a textbox and this works perfectly.

Any help would be greatly appreciated.

Brian
 
K

kaeli

On the parent_form.aspx I have these controls

<asp:listbox id="Operators" runat="server" Width="163px"
SelectionMode="Multiple" Rows="2"></asp:listbox>
<INPUT class="loButton" onclick="java script:getOptionPicker('?mid=TS5
&callingcontrol=Operators');" type="button" value="+">

onClick="getOptionPicker...

Drop that "javascript:" from it. Especially since there's a space in
there that will f* up other browsers besides IE. onClick in inherently a
javascript event. I don't think ASP changes that...
On the option_picker.aspx form I have these controls and functions

<asp:listbox id="destList" runat="server" SelectionMode="Multiple"
Width="100px" Height="134px" AutoPostBack="True"></asp:listbox>

autopostback submits the form, losing all javascript variables
associated with the page (and clearing all form elements?). That's
possibly why you're losing stuff. I see your text element does not use
autopostback.
<input id="Done" onclick="java script:addSelectedItemsToParent()"
type="button" value="Done" name="Done">

Try removing the autopostback from the select.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top