Groups | Blog | Home
all groups > asp.net building controls > april 2005 >

asp.net building controls : Can't retain state for Control inherted from ListBox


Don
4/21/2005 2:31:31 PM
I have created a Web Custom Control that inherits from
WebControls.ListBox but can't get it to retain the selectedIndex after
a postback. As a test I created a very simple version of the control
with no additional code. I just inherited from the exisiting ListBox
class and put the control on a page.

I put this control a blank page along with a button to perform a post
back. I select an item in the list box and then click the button and
after the postback I have lost the selected value. I added some
javascript to alert to the selectedIndex just to make sure the client
had one and it did.

EnableViewState is set to true for this control. If I make a custom
textbox in the same method it's value is retained after postback with
no additional code. If I put a standard ListBox on the page it's
selectedIndex is retained after postback with no additional code.

Thanks,
Don
recoil NO[at]SPAM community.nospam
4/26/2005 10:45:30 AM
Make sure that you are giving it the same ID and adding it to its
parent and that the parent is attached tothe page at the appropriate
time. Also try implementing INamingContainer.
AddThis Social Bookmark Button