小弟想做一个登陆窗体,如果密码和用户名捕捉正确就转到另外一个窗体上,我用了一个html文件做为start page,但是在登陆是出先了NullReferenceExcpetionwasunhandledbyusercode的warning,请哪位高手能帮小弟解决一下这个问题,谢谢了
代码如下using System;
using System.Data;
using System.Configuration;
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 _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string username = Request.Form.Get("userNametxt").ToString();
string password = Request.Form.Get("passwordtxt").ToString();
Response.Redirect("Default2.aspx");
}
}html网页的html代码如下:
<!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>Untitled Page</title>
</head>
<body>
<form method = "post" action = "Default.aspx">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 68px; height: 26px">
Username</td>
<td style="width: 147px; height: 26px">
<input id="usernametxt" type="text" /></td>
<td style="width: 263px; height: 26px">
</td>
</tr>
<tr>
<td style="width: 68px">
Password</td>
<td style="width: 147px">
<input id="passwordtxt" style="width: 151px" type="password" /></td>
<td style="width: 263px">
</td>
</tr>
<tr>
<td style="width: 68px; height: 26px">
</td>
<td style="width: 147px; height: 26px">
<input id="Submit1" type="submit" value="submit" /></td>
<td style="width: 263px; height: 26px">
</td>
</tr>
</table></form>
</body>
</html>
代码如下using System;
using System.Data;
using System.Configuration;
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 _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string username = Request.Form.Get("userNametxt").ToString();
string password = Request.Form.Get("passwordtxt").ToString();
Response.Redirect("Default2.aspx");
}
}html网页的html代码如下:
<!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>Untitled Page</title>
</head>
<body>
<form method = "post" action = "Default.aspx">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 68px; height: 26px">
Username</td>
<td style="width: 147px; height: 26px">
<input id="usernametxt" type="text" /></td>
<td style="width: 263px; height: 26px">
</td>
</tr>
<tr>
<td style="width: 68px">
Password</td>
<td style="width: 147px">
<input id="passwordtxt" style="width: 151px" type="password" /></td>
<td style="width: 263px">
</td>
</tr>
<tr>
<td style="width: 68px; height: 26px">
</td>
<td style="width: 147px; height: 26px">
<input id="Submit1" type="submit" value="submit" /></td>
<td style="width: 263px; height: 26px">
</td>
</tr>
</table></form>
</body>
</html>
解决方案 »
- 连接里面跳连接。怎么判断跳连接是否存在?
- momonn来教我一个ppt转pdf
- WebPart问题
- 都有什么常用的第三方控件?
- Request.Form
- 大家来讨论一下,Response.Redirect("1.aspx");与Response.Write("<script>location.href='1.aspx';</script>");
- dataset新添加的列为何得不到值?
- 高手请进:从excel导入数据到sql server时候出现的问题?
- 放假没事写了个基类库...请高手指点...
- 如何提高asp.net的运行效率
- 如何让服务器(静态IP)从网上邻居(是内网)读取大文件。高手请进。
- 应聘程序员工作
改成这样就行了
<input id="passwordtxt" name="passwordtxt" style="width: 151px" type="password" />
<input id="usernametxt" name="usernametxt" type="text" />
如果你想在服务端取到客户端的值一定要加入name属性,这样浏览才会把值发送到服务端