我是用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">
                密&nbsp; 码</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的数据没提交过来,还是没接收到
用了很多方法就像注释里面的一样~
小弟没多少分,希望哪位能指点小弟一下
万分感激~!!

解决方案 »

  1.   

    很少用这种方式了,记得以前asp时经常用。应该是你要指定html表单的name,而不只是指定id这个原因吧
      

  2.   

    <input id="txtUserName" name="txtUserName"  style="width: 176px; position: relative; height: 32px; left: 0px; top: 0px;" type="text" />这样试一下
      

  3.   


    string userName =Request.Params["txtUserName"].ToString();
    string userPwd =Request.Params["txtUserPwd"].ToString();
      

  4.   

    weizhuangzhi(壮志 不怕“不会”问问题,就怕“不会问”问题) 
    ====================对,要用name, 不是id 。呵呵
      

  5.   

    谢谢楼上两位啊~~应该是name 才行 呵呵
    十分感谢~不过我还想问一下
    ID 和 NAME 有什么区别呢~
      

  6.   

    javascript一般控制都是id
    以前的asp获取都是通过name
    aspx兼容了asp这种方式