Combo ListBox selected Index problem

J

Jacques

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
 
D

Dale

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
 
J

Jacques

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
 
D

Dale

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top