DropDownList selectedIndexChanged event not firing

Discussion in 'ASP .Net Web Controls' started by Dabbler, May 6, 2005.

  1. Dabbler

    Dabbler Guest

    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.
    Dabbler, May 6, 2005
    #1
    1. Advertising

  2. Dabbler

    Brock Allen Guest

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

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > 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.
    >
    Brock Allen, May 6, 2005
    #2
    1. Advertising

  3. Dabbler

    Dabbler Guest

    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.

    "Brock Allen" wrote:

    > Is it possible that you're rebuilding the list upon postback. This could
    > cause it to lose memory of the event, so to speak.
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    > > 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.
    > >

    >
    >
    >
    >
    Dabbler, May 6, 2005
    #3
  4. Dabbler

    Brock Allen Guest

    > 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.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen
    Brock Allen, May 6, 2005
    #4
  5. Dabbler

    Dabbler Guest

    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.

    "Brock Allen" wrote:

    > Is it possible that you're rebuilding the list upon postback. This could
    > cause it to lose memory of the event, so to speak.
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    > > 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.
    > >

    >
    >
    >
    >
    Dabbler, May 6, 2005
    #5
  6. Dabbler

    Dabbler Guest

    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!

    "Brock Allen" wrote:

    > > 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.
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    >
    >
    >
    Dabbler, May 6, 2005
    #6
  7. Dabbler

    Josh Behl Guest

    "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
    "Brock Allen" wrote:

    > > 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.
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    >
    >
    >
    Josh Behl, Aug 13, 2006
    #7
    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. DesignerX
    Replies:
    2
    Views:
    3,825
    Bob Carsto
    Nov 14, 2003
  2. Paul Lacey
    Replies:
    2
    Views:
    2,703
    =?Utf-8?B?TmlrYW5kZXIgJiBNYXJncmlldCBCcnVnZ2VtYW4=
    Feb 17, 2005
  3. Lew Barnesson
    Replies:
    3
    Views:
    803
    Lew Barnesson
    Dec 4, 2004
  4. =?Utf-8?B?Q3VybHlGcm8=?=

    dropdownlist selectedIndexChanged event not firing

    =?Utf-8?B?Q3VybHlGcm8=?=, Aug 14, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    2,620
    =?Utf-8?B?Q3VybHlGcm8=?=
    Aug 14, 2005
  5. BentleyInc

    DropDownList.SelectedIndexChanged event not firing

    BentleyInc, Dec 10, 2004, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    1,246
    Steven Cheng[MSFT]
    Dec 14, 2004
Loading...

Share This Page