DropDownList event not firing as expected

  • Thread starter Thread starter Mark Rae
  • Start date Start date
M

Mark Rae

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
 
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...?
 
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();">
 

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

Back
Top