更改母版页中的图片

时间:2011-08-10 05:45:26

标签: c# asp.net master-pages

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中更改图像???

3 个答案:

答案 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";

一步到位