No event fired when first item in dropdown select

Discussion in 'ASP .Net' started by hypomite, Aug 13, 2003.

  1. hypomite

    hypomite Guest

    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?
     
    hypomite, Aug 13, 2003
    #1
    1. Advertising

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



    "hypomite" <> wrote in message
    news:%...
    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?
     
    Ken Cox [Microsoft MVP], Aug 13, 2003
    #2
    1. Advertising

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


    "Ken Cox [Microsoft MVP]" <> wrote in message
    news:%...
    > 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
    >
    >
    >
    > "hypomite" <> wrote in message
    > news:%...
    > 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?
    >
    >
    >
     
    S. Justin Gengo, Aug 14, 2003
    #3
    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. Paperback Writer

    DropDown First Item

    Paperback Writer, Jun 10, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    355
    Brock Allen
    Jun 10, 2005
  2. PKin via DotNetMonster.com

    Placeholder and event not fired the first time.

    PKin via DotNetMonster.com, Oct 10, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    1,429
    S. Justin Gengo
    Oct 11, 2005
  3. Mike
    Replies:
    1
    Views:
    816
  4. James
    Replies:
    0
    Views:
    354
    James
    Jun 5, 2006
  5. sathya

    DataGrid Select Button Event not fired

    sathya, Oct 20, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    134
    Mark Fruhling
    Oct 21, 2005
Loading...

Share This Page