Multi list box selector and post back question

B

Brian Henry

I have two list boxes on my form... lstCanSend and lstRecipients... well
then there are two buttons add and remove between them (your basic select
and pick listing) which uses java script to move the items between list
boxes (the listbox controls are server side ones with runat=server set on
them, the buttons are basic html button i dont want to post back each time
someone clicks on add or remove... that wastes time and bandwidth) well the
add and remove buttons work, but at postback there is no data returned from
the lstRecipients listbox, because when the items were added through java
script it did not get posted back to data (i only want to post back when
thet user clicks on the OK button which sends this data to a processor) here
is my html code with the java script inside it... where should i do the post
back of the lstRecipient data and how do i do it when the user clicks on the
OK button? thanks


<%@ Register TagPrefix="cc1" Namespace="SecureEmail" Assembly="SecureEmail"
%>
<%@ Register TagPrefix="uc1" TagName="ctrlTop" Src="../Themes/ctrlTop.ascx"
%>
<%@ Register TagPrefix="uc1" TagName="ctrlBottom"
Src="../Themes/ctrlBottom.ascx" %>
<%@ Register TagPrefix="uc1" TagName="ctrlLeftSide"
Src="../Themes/ctrlLeftSide.ascx" %>
<%@ Register TagPrefix="uc1" TagName="ctrlRightSide"
Src="../Themes/ctrlRightSide.ascx" %>
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="AddressBook.aspx.vb" Inherits="SecureEmail.AddressBook" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>The Reschini Secure E-Mail Network</title>
<meta name="ProgId" content="SharePoint.WebPartPage.Document">
<meta name="WebPartPageExpansion" content="full">
<base target="_self">
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="VBScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<script language="javascript">
function movePersonTo(from,to)
{
// Move this person from this list box to that listbox
for (var i=0; i < from.options.length; i++)
{
var o = from.options;
if (o.selected)
{
to.options[to.options.length] = new Option(o.text,o.value,false,false);
}
}

// delete from original list
for (var i = (from.options.length - 1); i >= 0; i--)
{
var o = from.options;
if (o.selected)
{
from.options = null;
}
}

from.selectedIndex = -1;
to.selectedIndex = -1;
}

</script>
</HEAD>
<body bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0"
MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<table border="0" width="100%" id="table1" cellspacing="0"
cellpadding="0" height="100%">
<tr>
<td valign="top">
<uc1:ctrlTop id="CtrlTop1" runat="server"></uc1:ctrlTop></td>
</tr>
<tr>
<td valign="top" height="100%">
<table border="0" width="100%" id="table2" height="100%"
cellspacing="0" cellpadding="0">
<tr>
<td valign="top">
<uc1:ctrlLeftSide id="CtrlLeftSide1"
runat="server"></uc1:ctrlLeftSide></td>
<td valign="top" width="100%">
<TABLE id="table3" cellSpacing="0" cellPadding="0" width="100%"
bgColor="#a0c6e5" border="0"
class="ToolBar ">
<TR>
<TD>
<P align="left">
<asp:button id="btmCloseAddress" runat="server" Text="OK"
CausesValidation="False" Font-Size="8pt"></asp:button></P>
</TD>
<TD>
<P align="right"><FONT face="Verdana" size="1"></FONT>&nbsp;</P>
</TD>
</TR>
</TABLE>
<table border="0" width="100%" id="table6" cellspacing="0"
cellpadding="0">
<tr>
<td>
<cc1:ctrlPageHeaderBox id="ctrlPageHeaderBox" runat="server"
Font-Size="8pt" Text="Address Book" AutoPostBack="True"></cc1:ctrlPageHeader
Box></td>
</tr>
</table>
<table border="0" id="table4" cellspacing="0" cellpadding="5">
<tr>
<td><FONT face="Verdana" size="2"> Please choose the
recipients</FONT></td>
<td>&nbsp;</td>
<td><FONT face="Verdana" size="2"> Send to</FONT></td>
</tr>
<tr>
<td><asp:listbox id="lstCanSend" runat="server" Width="208px"
Height="168px" SelectionMode="Multiple"></asp:listbox>
</td>
<td>
<table border="0" width="100%" id="table5" height="100%"
cellspacing="0" cellpadding="0">
<tr>
<td><INPUT type="button" value="Add"
onclick="movePersonTo(this.form['lstCanSend'],this.form.lstRecipients)">
</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<P><INPUT type="button" value="Remove"
onclick="movePersonTo(this.form['lstRecipients'],this.form.lstCanSend)"></P>
</td>
</tr>
</table>
<P>&nbsp;</P>
<P>&nbsp;</P>
</td>
<td><asp:listbox id="lstRecipients" runat="server" Width="232px"
Height="166px" SelectionMode="Multiple"></asp:listbox>
</td>
</tr>
</table>
<p>&nbsp;</p>
</td>
<td valign="top">
<uc1:ctrlRightSide id="CtrlRightSide1"
runat="server"></uc1:ctrlRightSide></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top">
<uc1:ctrlBottom id="CtrlBottom1" runat="server"></uc1:ctrlBottom></td>
</tr>
</table>
</form>
</body>
</HTML>
 
S

Steven Cheng[MSFT]

Hi Brian,

As for the dropdownlist's items modification problem, I think this is
because the ASP.NET DropDownList server control or <select
runat="server">... (html server control) all store their items information
in the viewstate, so if we use the clientside script to modify their items
collection, it won't take effect when we post back the page to serverside.
Currently, I think you can consider the following two means;
1.Change the code to modify the list's item serverside (post back whenever
need to do modification)

2. still use client script, but we need to provide another place to store
the items info(or the modification info), for example, whenever we do
changes in the list, we store latest items collection in a <input
type=hidden> field. (use some split flag to separate the containg items).

In addition, here are some third-party list components which provide the
move list items between two list on both serverside or clientside, you may
also have a look:

#ListTransfer
http://www.asp.net/ControlGallery/ControlDetail.aspx?Control=1762&tabindex=2

#Ordered ListBox
http://www.asp.net/ControlGallery/ControlDetail.aspx?Control=1573&tabindex=2

Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
K

k r

In an attempt to postback my javascript-added items to my listbox, I
have declared the following hidden variable:

<input TYPE="hidden" NAME="hdnParts">

In Javascript, when I add an item to my listbox I also add it to this
hidden variable.

Then, in my button event, I parse the hidden control, extract the added
items and add it to the server side listbox:

Request.Form["hdnParts"].Split(';');

The problem I have is that I have a third party control on my page that
causes a reload (postback). Upon reload my hidden variable is gone and
if the above button is pressed after this reload,
Request.Form("hdnParts"] gives me an empty string. How do I preserve the
hidden input value between postbacks. Another words, how do I achieve
the following in the old ASP world:

<input TYPE="hidden" NAME="hdnParts" value=<%request.form("hdnParts"%>>
 

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,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top