Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

Handle the Click event, and get it's Name property:
C#
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:
C#
private void MyTextBox_Click(object sender, EventArgs e)
    {
    if (sender is TextBox tb)
        {
        Console.WriteLine(tb.Name);
        }
    }
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900