开发者

Getting the .Text value from a TextBox

开发者 https://www.devze.com 2023-01-08 16:39 出处:网络
I have a bunch of textboxes on my asp.net page, and on TextChanged e开发者_StackOverflow中文版vent, I want to run a stored proc to return a Name, based on user input. If I have a block of code like:

I have a bunch of textboxes on my asp.net page, and on TextChanged e开发者_StackOverflow中文版vent, 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?


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;


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


Did you try using t.Text?

0

精彩评论

暂无评论...
验证码 换一张
取 消