我是用HTML向ASPX中提交一个用户表单~在ASPX上读取并显示出来。
代码如下:
Login.html<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Index</title>
</head>
<body>
<form action="Login.aspx" method="post" runat="server">
<table style="left: 184px; position: relative; top: 32px">
<tr>
<td style="width: 54px; height: 30px">
用户名</td>
<td style="width: 181px; height: 30px">
<input id="txtUserName" style="width: 176px; position: relative; height: 32px; left: 0px; top: 0px;" type="text" /></td>
</tr>
<tr>
<td style="width: 54px; height: 30px">
密 码</td>
<td style="width: 181px; height: 30px">
<input id="txtUserPwd" style="width: 176px; position: relative; top: 0px; height: 32px; left: 0px;"
type="text" /></td>
</tr>
<tr>
<td colspan="2" style="height: 27px">
<input id="Reset" style="left: 165px; width: 50px; position: relative; top: 0px; height: 30px;"
type="reset" value="重置" onclick="return Reset1_onclick()" />
<input id="login" style="left: 8px; position: relative; top: 0px; width: 50px; height: 30px;" type="submit"
value="登陆" onclick="return login_onclick()" /></td>
</tr>
</table></form>
</body>
</html>Login.aspx.cs
using System;
using System.ComponentModel;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Drawing;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class Login : System.Web.UI.Page
{
private void Page_Load(object sender, EventArgs e)
{
string userName =Request["txtUserName"];
string userPwd =Request["txtUserPwd"];
//string userName = Request.Form.Get("txtUserName");
//string userPwd = Request.Form.Get("txtUserPwd");
//userName = Request.QueryString.Get("txtUserName");
//userPwd = Request.QueryString.Get("txtUserPwd");
//userName = Request.Form.Get("txtUserName");
//userPwd = Request.Form.Get("txtUserPwd"); if (userName == null && userPwd == null)
{
Response.Write("用户密码为空");
}
else
{
Response.Write(userName);
Response.Write(userPwd);
}
}
}
结果输出的是:用户密码为空.
我不请是不是HTML的数据没提交过来,还是没接收到
用了很多方法就像注释里面的一样~
小弟没多少分,希望哪位能指点小弟一下
万分感激~!!
代码如下:
Login.html<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Index</title>
</head>
<body>
<form action="Login.aspx" method="post" runat="server">
<table style="left: 184px; position: relative; top: 32px">
<tr>
<td style="width: 54px; height: 30px">
用户名</td>
<td style="width: 181px; height: 30px">
<input id="txtUserName" style="width: 176px; position: relative; height: 32px; left: 0px; top: 0px;" type="text" /></td>
</tr>
<tr>
<td style="width: 54px; height: 30px">
密 码</td>
<td style="width: 181px; height: 30px">
<input id="txtUserPwd" style="width: 176px; position: relative; top: 0px; height: 32px; left: 0px;"
type="text" /></td>
</tr>
<tr>
<td colspan="2" style="height: 27px">
<input id="Reset" style="left: 165px; width: 50px; position: relative; top: 0px; height: 30px;"
type="reset" value="重置" onclick="return Reset1_onclick()" />
<input id="login" style="left: 8px; position: relative; top: 0px; width: 50px; height: 30px;" type="submit"
value="登陆" onclick="return login_onclick()" /></td>
</tr>
</table></form>
</body>
</html>Login.aspx.cs
using System;
using System.ComponentModel;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Drawing;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class Login : System.Web.UI.Page
{
private void Page_Load(object sender, EventArgs e)
{
string userName =Request["txtUserName"];
string userPwd =Request["txtUserPwd"];
//string userName = Request.Form.Get("txtUserName");
//string userPwd = Request.Form.Get("txtUserPwd");
//userName = Request.QueryString.Get("txtUserName");
//userPwd = Request.QueryString.Get("txtUserPwd");
//userName = Request.Form.Get("txtUserName");
//userPwd = Request.Form.Get("txtUserPwd"); if (userName == null && userPwd == null)
{
Response.Write("用户密码为空");
}
else
{
Response.Write(userName);
Response.Write(userPwd);
}
}
}
结果输出的是:用户密码为空.
我不请是不是HTML的数据没提交过来,还是没接收到
用了很多方法就像注释里面的一样~
小弟没多少分,希望哪位能指点小弟一下
万分感激~!!
解决方案 »
- 怎么提高发邮件的速度?
- ASP.NET C#读取Excel单元格有问题
- C# 导出excel在本地测试通过,但是在服务器时就出错
- select问题,加入另一个表中的一个字段,并以此字段排序
- 自定义控件属性设置问题
- AjaxPro的问题
- 请问在BS结构的系统,如何在文本框中录入一个车牌的文字头一个拼音时,将其可能的几个文字都给出来,也不知道能不能下拉选择?
- 请教vs.net2003安装的问题
- xmlhttp是什么东西。。大家教教我
- 谁用过Wrox的Spinner控件?为何Spinner.Value总是空?或者谁能推荐一个微调控件~~
- 如何让一个button先在后台响应一个函数,然后再响应js。
- 分类排序,可拖动问题?
string userName =Request.Params["txtUserName"].ToString();
string userPwd =Request.Params["txtUserPwd"].ToString();
====================对,要用name, 不是id 。呵呵
十分感谢~不过我还想问一下
ID 和 NAME 有什么区别呢~
以前的asp获取都是通过name
aspx兼容了asp这种方式