/// 2.执行按钮事件,TextBox永远存在于Request.Form.Keys中
/// 3.CheckBox不管是服务器端控件还是Html控件,只在被选中时才包括在Keys中
/// 4.执行事件的那个Button也会包括在Request.Form.Keys中
/// 5.只要执行事件默认包括__VIEWSTATE与__EVENTVALIDATION
/// 博客园的高手谁能解释一下?我没有搜索到相关的信息,谢谢
单击Button1之后的效果:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FormKeys.aspx.cs" Inherits="test_FormKeys" %>
<!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>Request.Form.Keys保存的是什么?</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" />
<input name="chk1" id="chk1" type="checkbox" runat="server" />
<asp:TextBox ID="TextBox1" runat="server">hello</asp:TextBox>
<asp:CheckBox ID="chk2" runat="server" name="chk2" />
<input id="Submit1" type="submit" value="submit" onclick="form1.submit();" />
</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>Request.Form.Keys保存的是什么?</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" />
<input name="chk1" id="chk1" type="checkbox" runat="server" />
<asp:TextBox ID="TextBox1" runat="server">hello</asp:TextBox>
<asp:CheckBox ID="chk2" runat="server" name="chk2" />
<input id="Submit1" type="submit" value="submit" onclick="form1.submit();" />
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
/// <summary>
/// 1.这个Page_Load执行时Keys.Count为0,why?
/// 2.执行按钮事件,TextBox永远存在于Request.Form.Keys中
/// 3.CheckBox不管是服务器端控件还是Html控件,只在被选中时才包括在Keys中
/// 4.执行事件的那个Button也会包括在Request.Form.Keys中
/// 5.只要执行事件默认包括__VIEWSTATE与__EVENTVALIDATION
/// 博客园的高手谁能解释一下?我没有搜索到相关的信息,谢谢
/// </summary>
public partial class test_FormKeys : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Show();
}
protected void Button1_Click(object sender, EventArgs e)
{
Show();
}
protected void Button2_Click(object sender, EventArgs e)
{
Show();
}
private void Show()
{
Response.Write(Request.Form.Keys.Count.ToString() + "<br/>");
for (int i = 0; i < Request.Form.Keys.Count; i++)
{
string ctl = Request.Form.GetKey(i);
Response.Write(ctl + "<br/>");
}
}
}
using System.Data;
using System.Configuration;
using System.Collections;
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;
/// <summary>
/// 1.这个Page_Load执行时Keys.Count为0,why?
/// 2.执行按钮事件,TextBox永远存在于Request.Form.Keys中
/// 3.CheckBox不管是服务器端控件还是Html控件,只在被选中时才包括在Keys中
/// 4.执行事件的那个Button也会包括在Request.Form.Keys中
/// 5.只要执行事件默认包括__VIEWSTATE与__EVENTVALIDATION
/// 博客园的高手谁能解释一下?我没有搜索到相关的信息,谢谢
/// </summary>
public partial class test_FormKeys : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Show();
}
protected void Button1_Click(object sender, EventArgs e)
{
Show();
}
protected void Button2_Click(object sender, EventArgs e)
{
Show();
}
private void Show()
{
Response.Write(Request.Form.Keys.Count.ToString() + "<br/>");
for (int i = 0; i < Request.Form.Keys.Count; i++)
{
string ctl = Request.Form.GetKey(i);
Response.Write(ctl + "<br/>");
}
}
}