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
}
如何在masterpage中更改图像???
答案 0 :(得分:4)
Image First = new Image();
First = (Image)(Page.Master.FindControl("First"));
if (First != null)
{
First.ImageUrl = "image-path";
}
答案 1 :(得分:1)
在property
master page
public string ImagePath
{
get { return First.ImageUrl; }
set { First.ImageUrl = value; }
}
在内容页面中添加@MasterType页面指令,如下所示......
<%@ MasterType VirtualPath="~/master1.master" %>
tow.aspx
页面加载设置该属性...
protected void Page_Load(object sender, EventArgs e)
{
((master1)this.Master).ImagePath= "image_path";
}
答案 2 :(得分:-1)
((master)this.Master).image.Src = "~/images/titles/accesscontrol.jpg";
一步到位