Click here to Skip to main content
14,239,571 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have a form, where I click on a button and a new textbox is inserted. I want to click on the textbox and it returns me the name of this textbox. Someone help me.


What I have tried:

I do not even know how to start
Posted
Updated 18-Jun-19 4:03am
Comments
F-ES Sitecore 18-Jun-19 9:55am
   
Start by buying a book on whatever technology this is (WinForms? WebForms? MVC? WPF?) and going through it to learn the basics. You can't possibly learn a language from scratch by asking questions on a forum.
Member 11426986 18-Jun-19 9:57am
   
WINDOWS FORM

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Handle the Click event, and get it's Name property:
private void MyTextBox_Click(object sender, EventArgs e)
    {
    TextBox tb = sender as TextBox;
    if (tb != null)
        {
        Console.WriteLine(tb.Name);
        }
    }
Or if you have C#7:
private void MyTextBox_Click(object sender, EventArgs e)
    {
    if (sender is TextBox tb)
        {
        Console.WriteLine(tb.Name);
        }
    }
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100