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;
public partial
class MasterPage_Test : System.Web.UI.Page
{
protected void Page_Load(
object sender, EventArgs e)
{
// 在内容页用FindControl方法找到内容页中的控件 DropDownList ddl =
new DropDownList();
ddl = Master.Master.FindControl(
"ContentPlaceHolder1").FindControl(
"cph").FindControl(
"ddlPage")
as DropDownList;
Master.Master.FindControl(
"ContentPlaceHolder1").FindControl(
"cph").Controls.Add(
new LiteralControl(
"<br />内容页中的DropDownList的ClientID是:" + ddl.ClientID));
// 增加一个事件处理,该事件是在母版页定义的一个公共事件 Master.SelectedIndexChanged_ddlMaster +=
new CommandEventHandler(Master_SelectedIndexChanged_ddlMaster);
}
void Master_SelectedIndexChanged_ddlMaster(
object sender, CommandEventArgs e)
{
// CommandEventArgs已经在母版页中的公共事件“SelectedIndexChanged_ddlMaster”中指定 string selectedText = e.CommandName;
string selectedValue = e.CommandArgument.ToString();
ddlPage.SelectedValue = selectedValue;
}
protected void ddlPage_SelectedIndexChanged(
object sender, EventArgs e)
{
// 调用母版页的方法 Master.SetddlMaster(ddlPage.SelectedIndex);
}
}