System.Web.UI.WebControl.Textbox不包含Text的定义

System.Web.UI.WebControl.Textbox does not contain the definition of Text

我需要从网络表单的文本框中获取文本值。在文档中提到 System.Web.UI.WebControl.Textbox 有一个 属性 文本,但是当我尝试使用它时出现错误。

string FieldName= "";
string FieldValue="";
if (inputValues[i] is System.Web.UI.WebControls.TextBox)
{
  FieldName = inputValues[i].ClientID;
  FieldValue = inputValues[i].Text; // error
}

显示的错误是 System.Web.UI.WebControl.Textbox does not contain the definition of Text。如何从文本框控件获取文本值?

尝试将 inputValues[i] 转换为 System.Web.UI.WebControl.Textbox。然后访问 Text 属性:

FieldValue = ((System.Web.UI.WebControl.Textbox)(inputValues[i])).Text;