No event fired when first item in dropdown select

  • Thread starter Thread starter hypomite
  • Start date Start date
H

hypomite

I have an handler for the SelectedIndexChanged event of a dropdown box. I
have also set the AutoPostBack option to True. When you select any item
besides the first one, the event sucessfully fires. However, if you ever
(even after you have selected other options previously) select the first
option in the dropdown, the AutoPostBack fires(the page reloads), but the
event does not. This is the only element on my page and ViewState is enabled
for both the page and the dropdown control.

Whats the deal here?
 
Yup, this is a pain. Since you haven't changed the selection, the index hasn't
changed. Some people add a "---Select---" field to force users to make a move.

Ken

--
Microsoft MVPs have a question for *you*: Are you patched against the Worm?
http://www.microsoft.com/security/security_bulletins/ms03-026.asp



I have an handler for the SelectedIndexChanged event of a dropdown box. I
have also set the AutoPostBack option to True. When you select any item
besides the first one, the event sucessfully fires. However, if you ever
(even after you have selected other options previously) select the first
option in the dropdown, the AutoPostBack fires(the page reloads), but the
event does not. This is the only element on my page and ViewState is enabled
for both the page and the dropdown control.

Whats the deal here?
 
Here's a great solution to this problem:

Use the required field validator.

First give your drop down list a first value like: "Please Select"

DropDownList1.Items.Insert(0, "Please Select") '---If you need to add it
after a databind.

Set the required field validator to validate the drop down.

Set the required field validator's InitialValue property to the initial
text: "Please Select"

The only thing is if the drop down is set to autopost back then the
validator won't fire on the client side so in your selected index changed
handler use:

Page.Validate()

If Page.IsValid Then

'---Code to run when drop down list is changed.

End If



Sincerely,


--
S. Justin Gengo, MCP
Web Developer


Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
Back
Top