DropDownList event not firing as expected

Discussion in 'ASP .Net' started by Mark Rae, Oct 4, 2005.

  1. Mark Rae

    Mark Rae Guest

    Hi,

    Apologies, but I appear to be having a senior moment...

    I have a standard DropDownList webcontrol with a SelectedIndexChanged event,
    as follows:

    <asp:TableCell ColumnSpan=4 VerticalAlign=Middle>
    Select your delivery location:
    <asp:DropDownList ID="cmbShipping" Runat="server"
    OnSelectedIndexChanged="cmbShipping_SelectedIndexChanged"
    AutoPostBack="true">
    <asp:ListItem Value="0">&nbsp;</asp:ListItem>
    <asp:ListItem Value="1">United Kingdom</asp:ListItem>
    <asp:ListItem Value="2">European Union</asp:ListItem>
    <asp:ListItem Value="3">Rest of world</asp:ListItem>
    </asp:DropDownList>
    </asp:TableCell>


    And the code-behind is as follows:

    protected DropDownList cmbShipping;

    private void Page_Load(object sender, System.EventArgs e)
    {
    if(!Page.IsPostBack)
    {
    BindData();
    }
    }

    public void cmbShipping_SelectedIndexChanged(object sender, EventArgs e)
    {
    try
    {
    BindData();
    }
    catch (Exception ex)
    {
    CApplication.GlobalExceptionHandler(ex);
    }
    }

    private void BindData()
    {
    // code to do the data binding goes here...
    }


    Problem is that the cmbShipping_SelectedIndexChanged() event only fires if
    the SelectedValue of the DropDownList is greater than zero i.e. if I change
    it from 0 to any other value, the event fires, but if I change it back to
    zero the event doesn't fire...No errors are raised and, if I place a
    breakpoint on the BindData(); line within the event code, it doesn't even
    appear to jump into it...

    I'm clearly missing something totally obvious...

    Any assitance gratefully received.

    Mark
     
    Mark Rae, Oct 4, 2005
    #1
    1. Advertising

  2. Mark Rae

    Mark Rae Guest

    "Mark Rae" <> wrote in message
    news:...

    > Problem is that the cmbShipping_SelectedIndexChanged() event only fires if
    > the SelectedValue of the DropDownList is greater than zero i.e. if I
    > change it from 0 to any other value, the event fires, but if I change it
    > back to zero the event doesn't fire...No errors are raised and, if I place
    > a breakpoint on the BindData(); line within the event code, it doesn't
    > even appear to jump into it...


    Not only that - the event fires even if other controls on the page trigger
    the PostBack...

    Anyone got any thoughts on this...?
     
    Mark Rae, Oct 5, 2005
    #2
    1. Advertising

  3. Mark Rae

    Patirck Ige Guest

    Do you have any sort of validations on your page?
    Patrick

    "Mark Rae" <> wrote in message
    news:...
    > "Mark Rae" <> wrote in message
    > news:...
    >
    > > Problem is that the cmbShipping_SelectedIndexChanged() event only fires

    if
    > > the SelectedValue of the DropDownList is greater than zero i.e. if I
    > > change it from 0 to any other value, the event fires, but if I change it
    > > back to zero the event doesn't fire...No errors are raised and, if I

    place
    > > a breakpoint on the BindData(); line within the event code, it doesn't
    > > even appear to jump into it...

    >
    > Not only that - the event fires even if other controls on the page trigger
    > the PostBack...
    >
    > Anyone got any thoughts on this...?
    >
    >
     
    Patirck Ige, Oct 6, 2005
    #3
  4. Mark Rae

    Mark Rae Guest

    "Patirck Ige" <> wrote in message
    news:...

    > Do you have any sort of validations on your page?


    There is a form with a submit button which checks that the DropDownList in
    question doesn't have a selectedIndex of 0 before submitting it, as follows:

    <script>

    function submitPayPal()
    {
    if(document.frmDefault.cmbShipping.selectedIndex == 0)
    {
    alert('Please select a delivery
    location');document.frmDefault.cmbShipping.focus();
    return false;
    }
    }

    </script>

    And the corresponding HTML is:

    <input type="submit" value="Proceed to checkout" onclick="return
    submitPayPal();">
     
    Mark Rae, Oct 6, 2005
    #4
    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,868
    Bob Carsto
    Nov 14, 2003
  2. Paul Lacey
    Replies:
    2
    Views:
    2,721
    =?Utf-8?B?TmlrYW5kZXIgJiBNYXJncmlldCBCcnVnZ2VtYW4=
    Feb 17, 2005
  3. Lew Barnesson
    Replies:
    3
    Views:
    823
    Lew Barnesson
    Dec 4, 2004
  4. Paul L
    Replies:
    1
    Views:
    7,343
  5. =?Utf-8?B?Q3VybHlGcm8=?=

    dropdownlist selectedIndexChanged event not firing

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

Share This Page