Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identify which textbox has fired a text changed event

I have a number of text boxes that are dynamically created via code.

I would like to be able to assign a generic event handler to all the textboxes for the text changed even and then within the handler determine which text box has fired the event.

Code I have is:

txtStringProperty.TextChanged += TextBoxValueChanged;

private void TextBoxValueChanged(object sender, RoutedEventArgs e)
{
    string propertyName = // I would like the name attribute of the textbox here
}

Please let me know if you require anymore information.

like image 865
user589195 Avatar asked Jan 17 '23 16:01

user589195


1 Answers

The sender parameter contains which control has fired the event. You can cast it to a TextBox and get the name property from it:

string propertyName = ((TextBox)sender).Name;
like image 95
Sjoerd Avatar answered Jan 26 '23 01:01

Sjoerd