注册 登录
编程论坛 ASP.NET技术论坛

非静态字段、方法或属性“system_userInfo.TextBox1”要求对象引用”

kangaroonj 发布于 2013-10-08 03:48, 871 次点击
    [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
    public static string[] GetCityList(string prefixText, int count, string contextKey)
    {
        string strState = TextBox1.Text;//????
        此处需要从页面上的一个TextBox1取值,不知道怎么写?报错“非静态字段、方法或属性“system_userInfo.TextBox1”要求对象引用”。

        //获取自动完成的选项数据
        
        List<string> list = new List<string>();

        string sql = string.Format("select top {0} name from t_b_xzqh where right(codeno,2)='00' and (name like '%{1}%' or dbo.f_GetPy(name) like '%{1}%')order by codeno", count, prefixText);
        var dr = SQLBase.ExecuteReader(sql);

        while (dr.Read())
        {
            list.Add(dr[0].ToString());
        }
        return list.ToArray();
    }
3 回复
#2
shangsharon2013-10-08 19:04
方法是public static的,访问不到TextBox1.Text
如果去掉static应该是可以,但是不知道会不会影响你其他的地方.
#3
Jina_C2013-10-09 14:24
传个参数?
 public static string[] GetCityList(string prefixText, int count, string contextKey, TextBox txtbox)
    {
        string strState = TextBox1.Text;//????
        此处需要从页面上的一个TextBox1取值,不知道怎么写?报错“非静态字段、方法或属性“system_userInfo.TextBox1”要求对象引用”。
        操作txtbox这个textbox就可以了
        //获取自动完成的选项数据
        ……
    }
调用的时候GetCityList(perfixText,count,contextKey,txtbox);
#4
3037709572013-10-09 17:30
public static string[] GetCityList(string prefixText, int count, string contextKey,string strState);
将strState当做一个参数来传递,这个参数的值就是TextBox1.Text的值。
1