string username = Request["txtUsername"].ToString();
出现问题:未将对象引用设置到对象的实例。
不解,望解答

解决方案 »

  1.   

    你在URL里有写txtUsername=***吗?
      

  2.   

    语句本身应该没问题
    出现:未将对象引用设置到对象的实例
    应该是Request["txtUsername"]没有取到值 不是这个地方的错误
      

  3.   

    语句本身应该有问题Request["txtUsername"].ToString();如果Request["txtUsername"]取到的值是null呢?
    .ToString()就会报错.不可以这样写.
      

  4.   

    string username = Request["txtUsername"].ToString();---------------------------------该为:string username = Request["txtUsername"] != null ? Request["txtUsername"].ToString() : "";因为Request["txtUsername"]为空的时候调用ToString方法会报空引用错误。
      

  5.   

    我在vs2005中就这个错误,可是在2003中这样没有错误啊
    我用的是post方法,回leafsword_519(一度的温暖)
    string username = Request["txtUsername"] != null ? Request["txtUsername"].ToString() : "";
    那是不是页面传递参数都要这样写啊,这样很麻烦啊,请问有没有什么别的方便的方法啊?
      

  6.   

    回leafsword_519(一度的温暖)
    string username = Request["txtUsername"] != null ? Request["txtUsername"].ToString() : "";
    那是不是页面传递参数都要这样写啊,这样很麻烦啊,请问有没有什么别的方便的方法啊?------------------------------------------------------------------------那你就必须却你传递过来的参数肯定不为空,否则就该判断一下才获得值。
      

  7.   

    string username = string.Empty;
    if( Request["txtUsername"] != null )
    username = Request["txtUsername"].ToString();
    我觉得这样简洁多了
      

  8.   

    ?txtUsername=**你的url后面有上面的东西吗?就是 ** 有值吗?
      

  9.   

    就是一个登陆页面,获得用户名和密码的那个,不是get方法和这?txtUsername=**没关系吧!
    那为什么在vs2003就不用这样检验呢??不解
      

  10.   

    string username = Request["txtUsername"] != null ? Request["txtUsername"].ToString() : String.Empty;
    注意看一下在aspx页面中和cs文件的txtUserName都定义了吗?