首页 > 解决方案 > html 表单发布到 aspx 页面,标题字段未发布。Chrome 说请求是 GET,根本不显示表单数据

问题描述

下面是发帖页面:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Properties login</title>
</head>
<body>
    <form id="formstart"  method="POST" action="proplist.aspx">
        <table id="loginTable" class="center">
            <tr>
                <td><label >User name</label></td>
                <td><input type="text" name="usertext" text="asm"/></td>
            </tr>
            <tr>
                <td><label ID="passwd" >Password</label></td>
                <td><input type="text" name="passtext" text=""/></td>
            </tr>
            <tr>
                <td><label ID="Label2" >Press to continue</label></td>
                <td><input type="submit" value="Submit" /></td>
            </tr>
        </table>
    </form>
</body>
</html>

简单的html,没有asp,以防万一导致任何问题。这是目标aspx页面:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="proplist.aspx.cs" Inherits="PropertyW.proplist" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="formlist" runat="server">

         <div>
            <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="Comic Sans MS" Font-Size="Larger" ForeColor="#3333CC" Text="Property List"></asp:Label>
            <div id="loginResponse" runat="server" >not logged in
        </div>
         <div id="namePassed" runat="server"></div>
 
    </form>
</body>
</html>

这是后面的代码。

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PropertyW
{
    public partial class proplist : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                NameValueCollection nvc = Request.Form;
                string userName = "asm", password = "17kgrovE";
                string sName = Request.Form["usertext"];
                string sPass = nvc["passtext"];
                if (nvc.Count > 0)
                {
                    sName = nvc["usertext"] + ".nvc";
                }
                string sMsg = string.Format("name passed = {0}, nvc count = {1}", sName, nvc.Count);
                namePassed.InnerHtml = sMsg;
                if (!string.IsNullOrEmpty(sName))
                {
                    userName = sName;
                }

                if (!string.IsNullOrEmpty(sPass))
                {
                    password = sPass;
                }
                // CheckLogin(userName, password);
            }
        }
    }
}

这是 chrome 在网络选项卡中显示的内容。表单数据没有条目。在表单字段后面的代码中为空。(用户文本和密码)。即使代码是 POST,Chrome 也会将请求显示为 GET。

这是 chrome 在网络选项卡中显示的内容。

标签: htmlasp.netformswebpost

解决方案


推荐阅读