Combo ListBox selected Index problem

Discussion in 'ASP .Net Web Controls' started by Jacques, Jul 14, 2004.

  1. Jacques

    Jacques Guest

    Hi,

    I've got a user control with a couple of textboxes and one combo listbox.

    When the save button is clicked the textbox values are passed back no
    problem, but the combo listbox selectedIndex is not set even though it was
    selected.

    Any ideas?

    Thanks
    Jacques
    Jacques, Jul 14, 2004
    #1
    1. Advertising

  2. Jacques

    Dale Guest

    Search your code for where you populate the listbox. Is it happening before
    you test it on postback? Generally these issues are caused by
    re-initializing the control before testing the value on postback.

    Try stepping through your code in debug mode and you should see that
    happening.

    To fix it, make sure you either initialize your control only if
    (!IsPostBack) or if you must re-initialize it on each load, make sure you
    retreive the value first.

    Dale

    "Jacques" <> wrote in message
    news:cd315g$515$...
    > Hi,
    >
    > I've got a user control with a couple of textboxes and one combo listbox.
    >
    > When the save button is clicked the textbox values are passed back no
    > problem, but the combo listbox selectedIndex is not set even though it was
    > selected.
    >
    > Any ideas?
    >
    > Thanks
    > Jacques
    >
    >
    Dale, Jul 15, 2004
    #2
    1. Advertising

  3. Jacques

    Jacques Guest

    Thanks for the reply Dale.

    Unfortunately postback will occur no matter what, because this is a
    composite control.

    But when the user clicks the save button, I manage to avoid the reload of
    the values.

    Is there anything else you can think of?

    Thanks
    Jacques

    "Dale" <> wrote in message
    news:%...
    > Search your code for where you populate the listbox. Is it happening

    before
    > you test it on postback? Generally these issues are caused by
    > re-initializing the control before testing the value on postback.
    >
    > Try stepping through your code in debug mode and you should see that
    > happening.
    >
    > To fix it, make sure you either initialize your control only if
    > (!IsPostBack) or if you must re-initialize it on each load, make sure you
    > retreive the value first.
    >
    > Dale
    >
    > "Jacques" <> wrote in message
    > news:cd315g$515$...
    > > Hi,
    > >
    > > I've got a user control with a couple of textboxes and one combo

    listbox.
    > >
    > > When the save button is clicked the textbox values are passed back no
    > > problem, but the combo listbox selectedIndex is not set even though it

    was
    > > selected.
    > >
    > > Any ideas?
    > >
    > > Thanks
    > > Jacques
    > >
    > >

    >
    >
    Jacques, Jul 15, 2004
    #3
  4. Jacques

    Dale Guest

    I'm not sure what you mean by postback will occur no matter what; my
    suggestion was based on that assumption already.

    There is on scenario I have run across where IsPostback will give you
    potentially unexpected results. I have had a page before where, when the
    user hits the enter key without having a control focused that causes
    postback. In this case IsPostback can return false, even though the
    customer thinks he has submitted the form and the form does reload.

    In the case I am referring to, the customer would enter a number into an
    HTML textbox and hit enter without clicking the submit button. In the
    codebehind I tested IsPostback and in that case IsPostback was false, giving
    undesired results. I ended up having to test the textbox value as well; if
    it wasn't empty then I treated the load event as a postback event. Perhaps
    this is what is going on in your case. Just a thought.

    The previous suggestion and this one are the only two things I have seen
    cause values to be lost. Perhaps you could post some of your code.

    Dale


    "Jacques" <> wrote in message
    news:cd5dcc$ca1$...
    > Thanks for the reply Dale.
    >
    > Unfortunately postback will occur no matter what, because this is a
    > composite control.
    >
    > But when the user clicks the save button, I manage to avoid the reload of
    > the values.
    >
    > Is there anything else you can think of?
    >
    > Thanks
    > Jacques
    >
    > "Dale" <> wrote in message
    > news:%...
    > > Search your code for where you populate the listbox. Is it happening

    > before
    > > you test it on postback? Generally these issues are caused by
    > > re-initializing the control before testing the value on postback.
    > >
    > > Try stepping through your code in debug mode and you should see that
    > > happening.
    > >
    > > To fix it, make sure you either initialize your control only if
    > > (!IsPostBack) or if you must re-initialize it on each load, make sure

    you
    > > retreive the value first.
    > >
    > > Dale
    > >
    > > "Jacques" <> wrote in message
    > > news:cd315g$515$...
    > > > Hi,
    > > >
    > > > I've got a user control with a couple of textboxes and one combo

    > listbox.
    > > >
    > > > When the save button is clicked the textbox values are passed back no
    > > > problem, but the combo listbox selectedIndex is not set even though it

    > was
    > > > selected.
    > > >
    > > > Any ideas?
    > > >
    > > > Thanks
    > > > Jacques
    > > >
    > > >

    > >
    > >

    >
    >
    Dale, Jul 15, 2004
    #4
    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. Chris Thunell

    Listbox NOT retrieving Selected Index

    Chris Thunell, Jul 28, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    5,130
    Chris Thunell
    Jul 28, 2004
  2. K B
    Replies:
    2
    Views:
    654
  3. mldardy
    Replies:
    0
    Views:
    952
    mldardy
    Sep 28, 2010
  4. haiwen
    Replies:
    3
    Views:
    156
    haiwen
    Jul 14, 2003
  5. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    268
    Tomasz Chmielewski
    Mar 4, 2008
Loading...

Share This Page