从TextBox获取.Text值

use*_*521 12 c# asp.net textbox .net-3.5

我的asp.net页面上有一堆文本框,而在TextChanged事件中,我想运行一个存储过程,根据用户输入返回一个Name.如果我有一个代码块,如:

TextBox t = (TextBox)sender;
string objTextBox = t.ID;
Run Code Online (Sandbox Code Playgroud)

我怎样才能获得.TextobjTextBox 的值?

Kie*_*one 30

请改用:

string objTextBox = t.Text;

对象tTextBox.您调用的对象objTextBox被赋予了该ID属性TextBox.

所以更好的代码是:

TextBox objTextBox = (TextBox)sender;
string theText = objTextBox.Text;
Run Code Online (Sandbox Code Playgroud)


Dam*_*ash 8

if(sender is TextBox) {
 var text = (sender as TextBox).Text;
}
Run Code Online (Sandbox Code Playgroud)