简体   繁体   中英

ASP.NET: button event does not fire, as its being blocked by another event on dropdown occurs (uxFromDate_TextChanged)

I have a button which has a click event but its not firing on the first click. I suspect its something to do with that i am in dropdown box control so when i click the Button the event for the dropdown box occurs (textChanged) but it forgets about the click event :-)

Of course if i click it a second time it works.

Or if i click somewhere else first so that the event TextChange occurs and then click the Button the first time it executes..

Is this normal and what are more workarounds if any?

basically the TextChange event must fire but the button click event must fire as well.

All the events i am talking about are ASP.NET events.

here is some examples of the events i am using - both the button and dropdown

uxGetData is a button and uxToDate is a dropdown box

protected void uxGetData_Click(object sender, EventArgs e)
{

    BindGrid();
    RefreshBindings();

}

protected void uxToDate_TextChanged(object sender, EventArgs e)
{
    DateTime date;
    bool valid = DateTime.TryParse(uxToDate.Text, out date);

    if (valid)
    {
        MyDate myDate= _repository.GetBetweenDate(date);
        if (myDate!= null)
            uxToMyDate.SelectedValue = Convert.ToString(myDate.item);
    }
}

One way around is cancel the AutoPostBack of the drop down and use AJAX instead to update the oother drop down.

Second way around is to disable the button when the drop down selection is changed, using client side script, thus the user won't be able to click it - will prevent the confusion.

Can't think of third way around ATM so hope one of the above will be suitable. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM