Click to See Complete Forum and Search --> : Need help with vanishing listbox items


Vengeance
02-04-2004, 08:40 PM
Hey Everyone,

While not being too much of a newbie when it comes to programming in general I am however a total newbie when it's in regards to Javascript and asp.net.

What I am trying to do is to have a main form with an ASP:Listbox and Input button which when the user clicks the are then presented with a child window that has two more ASP:Listboxes and some more Input buttons. They are the allowed to move items around between the two listboxes on the child form until they are happy. At which point they then click the done button and their selection is passed back to the main form. Visually everything seems to work fine. The form comes up, items move around as expected, and are then returned to the main form listbox when done. However, when the user clicks an ASP:Button on the main form to save their information the contents of the listbox disappear.

I had a hard time trying to get each form able to recognize the other forms listbox but finally managed to get it this far. Most if not all of the inner workings are being done via javascript which I can post some snippets if anyone feels that might help. I was hoping that someone might be able to tell me if what I'm trying to do is even possible or not and if it is then what would be the best way to approach this so as to to if I'm going in the totally wrong direction.


TIA,

Brian

Kor
02-05-2004, 02:07 AM
Show us and maybe we could help

Vengeance
02-05-2004, 11:14 AM
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="javascript:getOptionPicker('?mid=TS5&amp;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,menubar=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[i] != null)
{destinationList.options[i] = new Option(sourceList.options[i].text, sourceList.options[i].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="javascript: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

Vengeance
02-09-2004, 11:37 AM
Hi again,

I still have yet to find an answer for this. And it appears that no one else has any suggestions. Could someone at least tell me if this should be possible or not so I know if I'm just wasting my time.

It seems like such a simple concept. Allow one form to manipulate the control of another form but the postback gets in the way.

Please, I beg of the great JavaScript gurus and gods to take pity on me :D

Kor
02-10-2004, 01:17 AM
It's just the ASP intrusions confuse me... I know nothing about ASP...