Getting the .Text value from a TextBox

220,672

Solution 1

Use this instead:

string objTextBox = t.Text;

The object t is the TextBox. The object you call objTextBox is assigned the ID property of the TextBox.

So better code would be:

TextBox objTextBox = (TextBox)sender;
string theText = objTextBox.Text;

Solution 2

if(sender is TextBox) {
 var text = (sender as TextBox).Text;
}

Solution 3

Did you try using t.Text?

Share:
220,672
user279521
Author by

user279521

.Net developer in training; working on multiple projects at any given time (austink_2004);

Updated on June 22, 2020

Comments

  • user279521
    user279521 almost 4 years

    I have a bunch of textboxes on my asp.net page, and on TextChanged event, I want to run a stored proc to return a Name, based on user input. If I have a block of code like:

    TextBox t = (TextBox)sender;
    string objTextBox = t.ID;
    

    how can I get the .Text value of objTextBox?