一个关于asp.net的问题,request获取html里面文本框的值的问题
这个是表单<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xh...
这个是表单<!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>
<form method="post" action="WebForm1.aspx">
<input id="txtUserName" type="text" />
<input id="ok" type="submit" value="确定"/>
</form>
</body>
</html>
WinForm1代码
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace request_response
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string username = Request.Form.Get("txtUserName").ToString();
Response.Write(username);
}
}
}
怎么会报这样的错
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 18: protected void Page_Load(object sender, EventArgs e)
行 19: {
行 20: string username = Request.Form.Get("txtUserName").ToString();
行 21: Response.Write(username);
行 22: }
源文件: D:\asp\request-response\request-response\WebForm1.aspx.cs 行: 20 展开
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
</head>
<body>
<form method="post" action="WebForm1.aspx">
<input id="txtUserName" type="text" />
<input id="ok" type="submit" value="确定"/>
</form>
</body>
</html>
WinForm1代码
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace request_response
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string username = Request.Form.Get("txtUserName").ToString();
Response.Write(username);
}
}
}
怎么会报这样的错
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 18: protected void Page_Load(object sender, EventArgs e)
行 19: {
行 20: string username = Request.Form.Get("txtUserName").ToString();
行 21: Response.Write(username);
行 22: }
源文件: D:\asp\request-response\request-response\WebForm1.aspx.cs 行: 20 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询