DropDownList selectedIndexChanged event not firing

D

Dabbler

My dropdown list with autopostback set to true is returning to the
application but my even handler for selectedIndexChanged isn't firing.
in InitializeComponent I have:
AddHandler Me.BrandSearch.SelectedIndexChanged, New EventHandler(AddressOf
Me.BrandSearch_SelectedIndexChanged)

in the handler I have:
Private Sub BrandSearch_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles BrandSearch.SelectedIndexChanged
Trace.Write("leftcolumNav", "insided index changed handler")
End Sub

Page Trace shows new value in variable, but the trace in event handler
doesn't appear.

Using .NET 1.1

Any suggestions would be greatly appreciated.
 
B

Brock Allen

Is it possible that you're rebuilding the list upon postback. This could
cause it to lose memory of the event, so to speak.
 
D

Dabbler

Thanks for you reply, Brock.

I tried it both ways. If I build the dropdownlist contents in Not IsPostBack
then the original page just refreshes with an empty list. The event does not
fire. I can test for changed index in IsPostBack but that's such a kludge.
Note the dropdownlist control is inside an ascx file and so is the handler. I
don't think that should matter. This is mod to StoreFront shopping cart which
by definition is a PITA to work with ;)

Thanks again.
 
B

Brock Allen

I tried it both ways. If I build the dropdownlist contents in Not
IsPostBack then the original page just refreshes with an empty list.
The event does not fire. I can test for changed index in IsPostBack
but that's such a kludge. Note the dropdownlist control is inside an
ascx file and so is the handler. I don't think that should matter.
This is mod to StoreFront shopping cart which by definition is a PITA
to work with ;)

Unless you've disabled ViewState, then you should only build the DDL when
IsPostBack==false. So this wounds like to me you've disabled ViewState? If
that's the case, then always build your DDL in Page_Init and you should see
better results.
 
D

Dabbler

Ok when I trace the postback SelectedIndex value I get -1. That implies that
the DropDownList object is no longer loaded with options. The options need to
be loaded at dynamically in Page_Load and that works, because I see the
options. Any suggestions on what I'm doing wrong?

Thanks much.
 
D

Dabbler

Ok that was it, the original page had view state disabled. When I turned it
back on the dropdownlist event works.

Thanks a bunch, I've spent hours on this rather simple mod!
 
J

Josh Behl

"then always build your DDL in Page_Init and you should see
better results"....that's the one that did it for me! Wow, what a pain. That helped me a ton. Nothing else worked until I found this post. Thank!

Josh
 

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,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top