ashkufaraz
ashkufaraz

Reputation: 5297

change picture in master page

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 masterpage ???

Upvotes: 0

Views: 3487

Answers (3)

user2830624
user2830624

Reputation: 1

((master)this.Master).image.Src = "~/images/titles/accesscontrol.jpg";

in one step

Upvotes: -1

Damith
Damith

Reputation: 63095

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

}

Upvotes: 1

Saurabh
Saurabh

Reputation: 5727

        Image First = new Image(); 
        First = (Image)(Page.Master.FindControl("First"));
        if (First != null)
        {
            First.ImageUrl = "image-path";
        }

Upvotes: 4

Related Questions