你把下面这段代码COPY到页面中看一下是不是你想要的:
Default.aspx
---------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server">1</asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server">2</asp:TextBox>
<asp:TextBox ID="TextBox3" runat="server">3</asp:TextBox>
<asp:TextBox ID="TextBox4" runat="server">4</asp:TextBox>
<asp:TextBox ID="TextBox5" runat="server">5</asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></div>
</form>
</body>
</html>
=======================================
Default.aspx.cs
--------------------------------------------
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
private Boolean IsTextBoxChange = false;
protected void Page_Load(object sender, EventArgs e)
{
TextBox CurBox = null;
foreach (Control Container in Page.Controls)
{
foreach (Control obj in Container.Controls)
{
CurBox = obj as TextBox;
if (CurBox != null)
{
CurBox.TextChanged += new EventHandler(this.DingXue);
}
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = IsTextBoxChange.ToString();
}
private void DingXue(object sender, EventArgs e)
{
IsTextBoxChange = true;
}
}