使用Request时,总是提示<未将对象引用设置到对象的实例>到底是那里的问题?
long.htm 代码如下:
<form action = "webform.aspx " method = "post " >
<input id= "txtUserName " type= "text " /> </td>
</tr>
<input id= "txtPassword " type= "text " /> </td>
</tr>
<input id= "Submit1 " type= "submit " value= "提交 " /> </td>
</tr>
</table>
</div>
</form>
</body>
</html>
///////////////////////////////////////////
webform.aspx.cs 文件里面的代码:
public partial class webform: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string username = Request[ "txtUserName "].ToString();
string password = Request [ "txtPassword "].ToString();
Response.Write(username + password);
}
}
//////////////////////////
每次运行提交时,会提示 <未将对象引用设置到对象的实例> 怎么办呀??
[解决办法]
<input name= "txtUserName " type= "text " /> </td>
</tr>
<input name= "txtPassword " type= "text " /> </td>
[解决办法]
孟大哥说了,这样应该就可以了,为了保险,其实可以把name= "txtUserName "和id= "txtUserName "都写上,呵呵,我有时候就这样