master1.master
HTML
<asp:Image ID="First" runat="server" />
tow.aspx
<%@ Page Language="C#" MasterPageFile="~/master1.master" AutoEventWireup="true"
CodeFile="two.aspx.cs" Inherits="ControlPanelPP"
Title="Untitled Page" %>
protected void Page_Load(object sender, EventArgs e)
{
how can change Image `First` in master1.master
}
how can change image in maste开发者_如何转开发rpage ???
Image First = new Image();
First = (Image)(Page.Master.FindControl("First"));
if (First != null)
{
First.ImageUrl = "image-path";
}
Define a property
in the code behind file of master page
public string ImagePath
{
get { return First.ImageUrl; }
set { First.ImageUrl = value; }
}
add @MasterType page directive in content page like this...
<%@ MasterType VirtualPath="~/master1.master" %>
tow.aspx
page load set that property...
protected void Page_Load(object sender, EventArgs e)
{
((master1)this.Master).ImagePath= "image_path";
}
((master)this.Master).image.Src = "~/images/titles/accesscontrol.jpg";
in one step
精彩评论