c# - 从 TextBox 获取 .Text 值

标签 c# asp.net .net-3.5 textbox

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

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

如何获取 objTextBox 的 .Text 值?

最佳答案

改用这个:

string objTextBox = t.Text;

对象 tTextBox。您调用 objTextBox 的对象被分配了 TextBoxID 属性。

更好的代码是:

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

关于c# - 从 TextBox 获取 .Text 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3334388/

相关文章:

c# - LDAPS 与 ASP.Net/C# 的连接

asp.net - 用户控制javascript

asp.net - 由于错误 : Error: Cannot find module "." at webpackMissingModule,预呈现失败

c# - .NET 中的多重继承有哪些好的替代方案?

c# - Visual Studio 风格的撤消下拉按钮 - 自定义 ToolStripSplitButton

c# - Json.Net:用于自定义命名的 JsonSerializer-Attribute

javascript - 使用ajax将html加载到Datatable子行中

c# - 通用自定义 linq 过滤器

c# - 不允许使用 WHERE 子句的 SqlDependency 查询。我怎样才能修改它是有效的?

c# - 更改 GroupBox 组件中的边框