如何将文本框值传递给方法或函数

时间:2010-10-19 06:25:21

标签: c# textbox asp.net-3.5

我有一个包含以下内容的CURPRFC类:

static public string CalcRFC(string firstname, string lastname, string middlename, string    date)

我在我的代码隐藏中调用此方法/函数如下:

CURPRFC.CalcRFC(txtfirstname.text, txtlastname.text, txtmidlename.text, txtdate.text)

其中每个值都是文本框值。但是,我收到一条错误说明:

System.Web.UI.WebControls.TextBox' does not contain a definition for 'text' and no extension method 'text' accepting a first argument of type 'System.Web.UI.WebControls.TextBox' could be found (are you missing a using directive or an assembly reference?)

我的C#有点弱。我想我需要将文本框文本值更改为字符串,但我不确定如何解决这个问题。我是在正确的轨道上吗?

非常感谢您的帮助!

谢谢, SID

1 个答案:

答案 0 :(得分:3)

您需要记住C#区分大小写。 TextBox没有text属性,但它具有Text属性:

CURPRFC.CalcRFC(txtfirstname.Text, txtlastname.Text,
                txtmidlename.Text, txtdate.Text);

(我还建议您考虑命名清晰度 - 通常C#变量使用camelCasing来表示单词中断,而名为“CURPRFC”的类远非不言自明。)