login.htm 和 main.aspx两个页 login.htm中放入表单 
<form method="post" action="main.aspx"> 
<input type="text" value="txtUserName"> 
<input type="submit" value="提交"> 
</form> main.aspx 的 page_load事件中 string username=Request.From.Get("txtUserName").toString(); 
Response.Write(username); 以login.htm页作为起始页运行  正常的话 在login.htm的txtUserName中写入的内容点击提交 后 会 跳转到 main.aspx页 并显示内容 但是 我这里 出现了错误 "用户代码未处理" "未将对象引用到对象的实例" . 排错显示中:"使用NEW关键字创建实例,在调用方法前检验对象是否为空" 我自己感觉没什么错误  无论是POST 还是 GET  都试过了 都不行  我用的VS2005  

解决方案 »

  1.   

    .net  不要这样传值      这不是asp.net体现的是页面与代码分离  处理代码直接就在asxp.cs中
      

  2.   

    你把login.htm换成login.aspx,试试看。
      

  3.   

    给你两种提交方式:①接受GET方法传来的数据q2_Request_Get.htm<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>使用Request对象</title>
    </head>
    <body>
        <center>
            <form action="q2_Request_Get_Action.aspx" method="get">        
                请输你的姓名:<input id="Text1" type="text" name="name"/><br />
                <input id="Submit1" type="submit" value="发送" />        
            </form>
        </center>
    </body>
    </html>
    q2_Request_Get_Action.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeFile="q2_Request_Get_Action.aspx.cs" Inherits="q2_Request_Get_Action" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <h4 style="text-align: center">
                接受GET方法传来的数据</h4>
            <p><%
                   string name = Request.QueryString["name"];
                   Response.Write("你的姓名为:" + name);
               %>
            </p>    
        </div>
        </form>
    </body>
    </html>
    q2_Request_Get_Action.aspx.csusing System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;public partial class q2_Request_Get_Action : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {    }
    }

    ②接受POST方法所传的数据q3_Request_Post.htm<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>无标题页</title>
    </head>
    <body>
    <center>
    <form action="q3_Post_Action.aspx" method ="post">
    请输入你的姓名:<input type="text" name="name" /><br />
    请输入你的性别:<input type="text" name="sex" /><br />
    请输入你的职业:<input type="text" name="occupation" /><br />
    <input type="submit" value="发送" id="submit1" name="submit1" />
    </form>
    </center>
    </body>
    </html>
    q3_Post_Action.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeFile="q3_Post_Action.aspx.cs" Inherits="q3_Post_Action" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <h4 style="text-align: center">
                接受POST方法所传的数据</h4>
            <%
                string name = Request.Form["name"];
                Response.Write("你的姓名为:" + name + "<br/>");
                string sex = Request.Form["sex"];
                Response.Write("你的性别为:" + sex + "<br/>");
                string occupation = Request.Form["occupation"];
                Response.Write("你的职业为:" + occupation  + "<br/>");  %>
        
        </div>
        </form>
    </body>
    </html>
    q3_Post_Action.aspx.csusing System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;public partial class q3_Post_Action : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {    }
    }
      

  4.   

    上面的只是传值的其中一种方法而已(实践能用),用Session也能传值....PS:偶学.net只有几个星期,不懂的地方还有很多,有好的方法大家来交流下吧。
      

  5.   

    你那种方法只能接受get方式的值。。post方式的值只能用Request.From["ID"];
      

  6.   

    <input type="text" value="txtUserName">中没有name属性,
    应为
    <input type="text" value="txtUserName" name="txtUserName">