Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Cannot retrieve a correct instance from a ListBox in a User Contro

Reply
Thread Tools

Cannot retrieve a correct instance from a ListBox in a User Contro

 
 
Pierre
Guest
Posts: n/a
 
      03-02-2005
Hello,

I'm trying to develop a simple Web User Control that contains two list
boxes, Add and Remove buttons. This User Control transfers the selected
items from left list box to right list box and vice-versa, depending on the
button clicked. The SelectionMode of both list boxes is "Multiple" and
AutoPostBack is set to false.

Here is the simple process:
string strItemsToKeep = "";
// Collect all items selected from lbLeftList list box.
foreach( ListItem item in lbLeftList.Items )
{
if( item.Selected )
{
lbRightList.Items.Add( item.Text );
}
else
{
strItemsToKeep = strItemsToKeep + item.Text + ";";
}
}
Then after the loop, I process the string and load it back to the left list
box. This works great within a simple aspx page.

But, here's my problem:
In a User Control ascx page, in the Code Behind, for each item retrieved
from lbLeftList, I can see the data in each item.Text but the item.Selected
is always false.

After searching on the Web, I tried the following:
System.Web.UI.UserControl UserControl;
UserControl =
(System.Web.UI.UserControl)Parent.FindControl("Dou ble_list_control1");
//which is the name of the User Control in the parent page.

System.Web.UI.WebControls.ListBox lb;
lb = (System.Web.UI.WebControls.ListBox)UserControl.Fin dControl("lbLeftList");

I thought that I could finally retrieve the correct information but, once
again, I have the same problem: the lb.Items[0].Selected (which is the one I
selected) is also set to false.

I really do not understand what is going on. If somebody can help me it
will greatly be appreciated.

Thank you very much.
--
Pete
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check whether user put a check in a toolbox CheckBox contro JB ASP .Net 1 08-26-2009 11:18 PM
How can I gatherinformation from a dynamically created user contro =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= ASP .Net 2 08-29-2007 02:14 PM
Loading user control when a link is clicked on another user contro =?Utf-8?B?U3JpZGhhcg==?= ASP .Net 1 11-18-2005 03:00 AM
Incorrect clientID for Calendar control as part of web user contro =?Utf-8?B?TWFyY0RlVm9zLkJF?= ASP .Net 0 07-20-2004 10:00 AM



Advertisments