views:

97

answers:

3

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?

+2  A: 

Did you try using t.Text?

SWeko
wow. That was easy. I kept trying objTextBox.Text
user279521
+5  A: 

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;
Kieren Johnstone
I need .ID to check if the user input was on txtApproverID (the populate Approver name with stored proc result), if user enterd Manager ID, then enter Manager name, if DirectorID etc.
user279521
Duh. Thanks @K. I need intravenous coffee
user279521
+4  A: 
if(sender is TextBox) {
 var text = (sender as TextBox).Text;
}
Vash