开发者

change picture in master page

开发者 https://www.devze.com 2023-03-27 03:07 出处:网络
master1.master HTML <asp:Image ID=\"First\" runat=\"server\" /> tow.aspx <%@ Page Language=\"C#\" MasterPageFile=\"~/master1.master\" AutoEventWireup=\"true\"

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

0

精彩评论

暂无评论...
验证码 换一张
取 消