EDIT:. According to another comment you made, if your text fields are added and removed programmatically, you can also create a custom control using the button and text field and implement this logic, and then programmatically add that user control. This is so that one button and text field will be connected to each other and do not know the others. I am not sure about the context in which you want to do this, so this approach may not be the best.
Use the textboxIsDirty flag that you set and disable in two event handlers.
private bool tpriceIsDirty = false; void tprice_TextChanged(object sender, EventArgs e) { tpriceIsDirty = true;
As suggested in another answer, I would also execute the current logic in the TextChanged method in the Click method. However, you can bind the tpriceIsDirty flag to the bsave.Enabled property to completely disable the button if the text field remains unchanged. This is better in terms of UX. :)
Edit: According to the comment you made, you can also add and remove event handlers on the fly. A variant of this approach may be useful to you.
void tprice_TextChanged(object sender, EventArgs e) { if (bsave.Click == null) { bsave.Click += bsave_Click; } .... } protected void bsave_Click(object sender, EventArgs e) { bsave.Click = null; }
source share