Dynamically get textbox's name

1.3k views Asked by At
private void txt_f_name_TextChanged(object sender, TextChangedEventArgs e)
{
    string textbox_name_1,textbox_name_2;            

    TextBox textbox_1 = (TextBox)e.Source;
    textbox_name1= textbox_1.Text;

    TextBox textbox_2 = (TextBox)e.OriginalSource;
    textbox_name_2;= textbox_2.Text;            
}

now both textbox_name_1 and textbox_name_2 are getting same result.

if i try to get another thing like text,with etc... these are also getting the same result....

but i think there may be some difference.

so,i want to know the major difference between e.source and e.OriginalSource.

2

There are 2 answers

0
Damith On

There are cases source and original source differ.

Common cases where the source may be adjusted include content elements inside a content model for a control (the contents of a list item, for instance, will report the list item element as the Source and the actual element within the list item will be the OriginalSource.

ref from MSDN:

i'm not sure what you try to do with your code. to check source and original source text property do like below, and you can do the same thing by adding list view with items having text box.

private void txt_f_name_TextChanged(object sender, TextChangedEventArgs e)
{
    string textbox_name_1,textbox_name_2;            

    TextBox textbox_1 = (TextBox)e.Source;
    textbox_name1= textbox_1.Text;

    TextBox textbox_2 = (TextBox)e.OriginalSource;
    textbox_name_2 = textbox_2.Text;            
}
0
paparazzo On

From the documentation

This originalsource property acquires its value once, before the class event handlers or any instance handlers are invoked, and is never adjusted past this point.

With routed events other events may have fired before your handler.

[OriginalSourece][1] http://msdn.microsoft.com/en-us/library/system.windows.routedeventargs.originalsource.aspx