Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a TextBox on a winforms form named "txtName". Now I want to show the value of the TextBox named "txtName" by fetching that TextBox control by its name, which is stored in a string variable.

Thank you!
Posted
Updated 21-Oct-11 22:44pm
v2
Comments
OriginalGriff 22-Oct-11 3:51am    
I'm sure English is not your native language, but it is the default language for this site.
In English, your question makes no sense at all.
Please, either try to find a better translation of your question to English, or find a site in your own native language, as they may be able to help you better than we can!
Use the "Improve question" widget to edit your question and provide better information.
Xeshan Ahmed 22-Oct-11 4:31am    
i think he want to get text of txtName(or some variable name)
Manfred Rudolf Bihy 22-Oct-11 4:46am    
I took off my tinfoil hat and did some editing of OP's question.
OriginalGriff 22-Oct-11 4:47am    
Ah-Ha! So, it is true, you also have a tin-foil hat...
Xeshan Ahmed 22-Oct-11 5:22am    
nice effort

1 solution

Its quite simple, to get value simply send the string with stored name to following method and get its text
C#
private string GetControlValue(string ControlName)
{
    Control[] ctrls = this.Controls.Find(ControlName, true);
    return ctrls[0].Text;
}
 
Share this answer
 
Comments
Manfred Rudolf Bihy 22-Oct-11 4:48am    
I think that is what OP was looking for! 5+

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