Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make sure the textchanged event of a textbox is fired before the click event of a button?

I have textboxes and a button.

The button uses a value which is manipulated by the textbox textchanged event.

I don't want the button click event to be fired before the value is changed by the textbox changed event.

 void tprice_TextChanged(object sender, EventArgs e) {
      idtextbox tsender = (idtextbox)sender;
      decimal value = 0;
      decimal.TryParse(tsender.Text, out value);
      if (area_updates.ContainsKey(tsender.id)) { area_updates[tsender.id].price = value; }
      else { area_updates.Add(tsender.id, new area_update(tsender.id) { price = value }); }
      Session["area_updates"] = area_updates;
    }

 protected void bsave_Click(object sender, EventArgs e) {

    }
like image 201
Uğur Gümüşhan Avatar asked Oct 31 '22 09:10

Uğur Gümüşhan


1 Answers

Afaik there is no way to ensure the event order TextChanged->ButtonClick. You should use a different approach.

  1. Move the TextChanged logic into the ButtonClick event or
  2. Make the TextBox AutoPostBack=true, but this requires an additional postback

So i would suggest to put the logic into the ButtonClick- and remove the TextChanged event.

like image 91
Tim Schmelter Avatar answered Nov 08 '22 04:11

Tim Schmelter