代码之家  ›  专栏  ›  技术社区  ›  SidC

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

  •  0
  • SidC  · 技术社区  · 14 年前

    我有一个包含以下内容的类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有点弱。我认为我需要将文本框的文本值更改为字符串,但不确定如何执行此操作。我走对了吗?

    非常感谢您的帮助!

    谢谢, 希德

    1 回复  |  直到 9 年前
        1
  •  3
  •   Jon Skeet    14 年前

    text 属性,但它确实具有 Text 财产:

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

    (我还建议您考虑一下命名清晰性-传统的C变量使用 camelCasing 表示分词,而一个名为“curprfc”的类远不能解释。)