HELP! dropdown resets to a specific value on postback! (asp.net.vb)

M

Mad Scientist Jr

I don't know how this is happening, but a dropdown control I have is
resetting to the 2nd value on the list anytime a postback occurs.

I have no initiation code outside of
If Not (IsPostBack)

I have EnableViewState set to true for the control - the control stays
populated, it just is losing its selected value.

The control is not contained in any panels or anything, just a Web
form, and the page's enabledViewState is also set to true.

I have tried disabling the autoPostBack of the dropdown, but it still
gets reset on any kind of postback.

I have tried enabling/disabling Smart navigation but it made no
difference.

This seems to have happened after I copied a dropdown form another
aspx page (which is identical, same name, properties, etc), and pasted
it on this screen. Now I get the problem with the control on both
screens. On both screens I have deleted the controls and dragged on
new ones, tried naming them different things, etc, but still I get
this problem.

I had a CompareValidator attached to the control, but deleted it to
see if that would help, but no such luck.

I tried to find where the control is losing its value it seems to be
getting reset before Page_Load because if I put an Exit Sub at top of
page load (moved initiation code into a button) I still get the
problem.

I started playing with events to see what is firing on postback. On
the first postback after I have changed the value,
Dropdown1_SelectedIndexChanged fires, followed by Dropdown1_PreRender.
Then on every subsequent postback Dropdown1_Load fires, followed by
PreRender. I don't know what those events are doing but maybe the
value is being reset there? Nowhere else in my app do I even reference
the dropdown except in the initialization.

I fear that due to some VS glitch I may have somehow corrupted my app
when I copied/pasted the control. I am using VS.NET 2003.

Has anyone seen anything like this? Any help appreciated!
 
M

Mad Scientist Jr

FOUND THE PROBLEM!!!!

I believe it had to do with the data not being unique.

cboCombo.Items(iCounter).Value = (my non-unique field)

I checked my SQL query I was populating the dropdown with and it
turned out to be the wrong field, and was sticking a non-unique value
into the dropdown's value property. I changed the field being returned
by SQL to the primary key (a unique value) and the problem went away.
 

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

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top