ListBox in composite control. SelectedItem not available.

Discussion in 'ASP .Net' started by shantanu_kush@hotmail.com, Jul 24, 2006.

  1. Guest

    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..
    , Jul 24, 2006
    #1
    1. Advertising

  2. Guest

    Hi all,

    The problem was that 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..
    , Jul 25, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike

    ListBox and SelectedItem.Value

    Mike, Jul 13, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    719
  2. Dave
    Replies:
    2
    Views:
    1,654
  3. Ohad Asor
    Replies:
    7
    Views:
    11,124
    John.Net
    Jul 11, 2005
  4. Chad
    Replies:
    0
    Views:
    219
  5. Ohad Asor

    Please Help: ListBox.SelectedItem returns null

    Ohad Asor, Jul 11, 2005, in forum: ASP .Net Web Controls
    Replies:
    7
    Views:
    223
    John.Net
    Jul 11, 2005
Loading...

Share This Page