现在是在一个html页里放了一个form,就是一个用户登陆的,这是FORM的<form action="Default2.aspx" method="post">
    <center><table style="width: 470px; height: 185px" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td style="width: 100px">
            </td>
            <td style="width: 245px">
                <input id="txtUserName" type="text" onclick="return txtUserName_onclick()" /></td>
            <td style="width: 280px">
            </td>
        </tr>
        <tr>
            <td style="width: 100px">
            </td>
            <td style="width: 245px">
                <input id="txtUserPwd" type="text" onclick="return Text1_onclick()" /></td>
            <td style="width: 280px">
            </td>
        </tr>
        <tr>
            <td style="width: 100px">
            </td>
            <td style="width: 245px">
                <input id="Submit1" type="submit" value="提交" onclick="return Submit1_onclick()" /></td>
            <td style="width: 280px">
            </td>
        </tr>
    </table>
    </center>
</form>
这个是ASPX页里的,
using 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 Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        String userName = Request["txtUserName"].ToString();
        String userPwd = Request["txtUserPwd"].ToString();
        //string userName=Request.Form.Get("txtUsername").ToString();
        //string userPwd=Request.Form.Get("txtUserPwd").ToString();
        Response.Write("登陆的用户名为" + userName + ";密码为" + userPwd);
    }
    protected void Text1_ServerChange(object sender, EventArgs e)
    {
      
    }
}
现在运行调试的时候就会出现  用户代码未处理NullRefrenceExpretion是什么意思? 没将引用对象设置到对象实力 指的是这句:String userName = Request["txtUserName"].ToString();
不大明白什么意思,谢谢大家帮忙下!

解决方案 »

  1.   

    加个判断就可以了
    if(Request["txtUserName"] != null)
    {
        String userName = Request["txtUserName"].ToString();
    }
      

  2.   

    if(IsPostBack)
    {
    String userName = Request["txtUserName"].ToString();
            String userPwd = Request["txtUserPwd"].ToString();
            //string userName=Request.Form.Get("txtUsername").ToString();
            //string userPwd=Request.Form.Get("txtUserPwd").ToString();
            Response.Write("登陆的用户名为" + userName + ";密码为" + userPwd);}
      

  3.   

    好象不对!这个只处理前部分,没考虑到后面的!还是要谢谢你!
    各位大虾帮看看啊!
    对了 是不是VS2005和VS2003有区别啊 我是在VS2005上运行的!