http://topic.csdn.net/u/20090703/09/8ba3c95d-26f0-4fe7-86ba-ba035a5a2747.html?19679
MasterPage.master
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!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:Button ID="btn11" runat="server" Text="Button" /> <br />
<asp:Button ID="btn12" runat="server" Text="Button" /><br />
<asp:Button ID="btn13" runat="server" Text="Button" /><br />
<asp:Button ID="btn14" runat="server" Text="Button" /><br />
<asp:Button ID="btn15" runat="server" Text="Button" /><br />
<asp:Button ID="btn16" runat="server" Text="Button" /><br />
<asp:Button ID="btn17" runat="server" Text="Button" /><br />
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>
test8.aspx
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="test8.aspx.cs" Inherits="test8" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Button ID="btn1" runat="server" Text="Button" /> <br />
<asp:Button ID="btn2" runat="server" Text="Button" /><br />
<asp:Button ID="btn3" runat="server" Text="Button" /><br />
<asp:Button ID="btn4" runat="server" Text="Button" /><br />
<asp:Button ID="btn5" runat="server" Text="Button" /><br />
<asp:Button ID="btn6" runat="server" Text="Button" /><br />
<asp:Button ID="btn7" runat="server" Text="Button" /><br />
<asp:Button ID="Button9" runat="server" OnClick="Button9_Click" Text="test" />
</asp:Content>
test8.aspx.cs
protected void Button9_Click(object sender, EventArgs e)
{
ContentPlaceHolder c = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
object[] btn = new object[7];
for (int i = 1; i < 8; i++)
{
btn[i - 1] = (Button)c.FindControl("btn" + i.ToString());
((Button)btn[i - 1]).Text = "修改" + i.ToString();
}
object[] btn2 = new object[7];
for (int j = 1; j < 8; j++)
{
btn2[j-1] = (Button)Page.Master.FindControl("btn" + (j+10).ToString());
((Button)btn2[j-1]).Text = "修改" + (j+10).ToString();
}
}