当前位置: 代码迷 >> ASP.NET >> request取值时"未将对象引用设置到对象的实例"是什么东东啊
  详细解决方案

request取值时"未将对象引用设置到对象的实例"是什么东东啊

热度:5941   发布时间:2013-02-26 00:00:00.0
request取值时"未将对象引用设置到对象的实例"是什么错误啊?
<body>
        <form   id= "form1 "   runat= "server "   action= "get.aspx ">
        <div>
                <asp:TextBox   ID= "iname "   runat= "server "> </asp:TextBox> <br   />
                <asp:TextBox   ID= "password "   runat= "server "> we </asp:TextBox> <br   />
                <asp:Button   ID= "Button1 "   runat= "server "   Text= "Button "   OnClick= "Button1_Click "   /> &nbsp; </div>
        </form>
</body>
</html>

c#文件为
  Response.Redirect( "get.aspx ");

get.aspx为
public   partial   class   get   :   System.Web.UI.Page
{
        protected   void   Page_Load(object   sender,   EventArgs   e)
        {
                //string   thename   =   Request.QueryString[ "iname "].ToString();
                //string   thepasswore   =   Request.QueryString[ "password "].ToString();
                string   thename,   thepassword;
                thename   =   Request.Form[ "iname "].tostring();
                thepassword   =   Request.Form[ "password "].tostring();
                Response.Write(thename+ " <br> ");
                Response.Write(thepassword);
        }
}
用的   vs2005的。     编译结果 "未将对象引用设置到对象的实例 "是什么错误啊?

------解决方案--------------------------------------------------------
thename = Request.Form[ "iname "].tostring();
你的 "iname " 在哪传的?
------解决方案--------------------------------------------------------
thename = Request.Form[ "iname "].tostring();
thepassword = Request.Form[ "password "].tostring()
这两个其中有错误~如果你iname或者怕ssword的值为null~用tostring就会提示这样的错误
------解决方案--------------------------------------------------------
加上判断就不错了
if (Request.Form[ "iname "] != null)
{
thename = Request.Form[ "iname "].ToString();
}
else
{
thename = "hello ";
}
if (Request.Form[ "password "] != null)
{
thepassword = Request.Form[ "password "].ToString();
}
else
{
thepassword = "world ";
}
页面第一次加载输出为:
hello
world
点击按钮之后:就是在文本框中输入的值
------解决方案--------------------------------------------------------
等等,貌似看错了你的问题,你的意思是 <asp:TextBox ID= "iname " runat= "server "> </asp:TextBox> 在一个页面,然后将这些值传到get.aspx页面?
如果这样的话,Response.Redirect( "get.aspx ");又没有传值过去,到底是什么意思?
  相关解决方案