Visual Basic .NET » ASP.NET General Discussion
ListBox in composite control. SelectedItem not available. -- Shawn --


Hi all,

I have a ListBox in a composite control. EnableViewState for the ListBox is true.

The ListBox is populated with some values.

The user makes a selection in the ListBox and then Clicks a Button.

In the Button Click event, I want to get the SelectedItem of the ListBox.

The SelectedItem valued is coming to be null.. Also, the ListBox is not preserving it's ViewState.

Any advice.

Thanks.

Shantanu..

-- CharlesCarroll --


If you populate the listbox everytime the page postbacks that is the sympton you describe.

postback=false is the only time you need to populate the listbox.

On 7/24/06, Shawn <shantanu_kush> wrote:

Hi all,

I have a ListBox in a composite control. EnableViewState for the
ListBox is true.

The ListBox is populated with some values.

The user makes a selection in the ListBox and then Clicks a Button.

In the Button Click event, I want to get the SelectedItem of the
ListBox.

The SelectedItem valued is coming to be null.. Also, the ListBox is not
preserving it's ViewState.

Any advice.

Thanks.

Shantanu..
 

-- Shawn --


Hi all,

The problem was that the EnsureChildControls should be called from the OnInit() override

protected override void OnInit(EventArgs e)
{
EnsureChildControls();
base.OnInit (e);
this.AttachEvents();
}

It works very well now.. Thanks for ur efforts.

Shantanu..

[Submit Comment]Home