不错呦!smile@林凯西,确保“准备文件”中的几个文件都有安装,S...您好,看了您这篇帖子觉得很有帮助。但是有个问题想请...我的修改过了怎么还被恶意注册呢 @jjjjiiii 用PJ快9年了,主要是A...PJ3啊,貌似很少有人用PJ了,现在不是WP就是z...@332347365,我当时接入时错误码没有-10...楼主,ChkValue值应为-103是什么意思呢?...大哥 你最近能看到我发的信息,请跟我联系,我有个制...
ASP.NET页面"不能"获取HTML表单post提交的参数值
编辑:dnawo 日期:2009-11-12
新建一个ASP.NET页面,从工具箱中拉一个HTML的Input(Text)控件和标准Button控件,并写相关代码:
Req.aspx:
Req.aspx.cs:
怎么提交,Request.Form["Text1"]始终没有值。后来发现,给Text1加上runat="server",就能正常获取值了-_-,今天在同事的提醒下,发现原来VS默认没有给控件添加name属性,添加上去就正常了:
那为什么加上runat="server"也可以呢?查看了下网页源代码,发现加了runat="server"后,在生成的源代码中自动加上了name属性!
Req.aspx:
复制内容到剪贴板
程序代码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Req.aspx.cs" Inherits="Req" %>
<!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 runat="server">
<title>HTML表单提交测试-Mzwu.Com</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Text1" type="text" />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
</body>
</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 runat="server">
<title>HTML表单提交测试-Mzwu.Com</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Text1" type="text" />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
</body>
</html>
Req.aspx.cs:
复制内容到剪贴板
程序代码

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
public partial class Req : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(Request.Form["Text1"]);
}
}
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
public partial class Req : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(Request.Form["Text1"]);
}
}
怎么提交,Request.Form["Text1"]始终没有值。后来发现,给Text1加上runat="server",就能正常获取值了-_-,今天在同事的提醒下,发现原来VS默认没有给控件添加name属性,添加上去就正常了:
复制内容到剪贴板
程序代码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Req.aspx.cs" Inherits="Req" %>
<!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 runat="server">
<title>HTML表单提交测试-Mzwu.Com</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Text1" type="text" name="Text1" />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
</body>
</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 runat="server">
<title>HTML表单提交测试-Mzwu.Com</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Text1" type="text" name="Text1" />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
</body>
</html>
那为什么加上runat="server"也可以呢?查看了下网页源代码,发现加了runat="server"后,在生成的源代码中自动加上了name属性!






评论: 0 | 引用: 0 | 查看次数: 10021
发表评论
请登录后再发表评论!