Set Background Image on a ContentPlaceHolder !!
Hi,
I have a child Login.aspx with Master page "Site.Master". I want that every time, user comes on Login page, then different images should be shown.
In my Login.aspx :
<%@ MasterType VirtualPath="~/Site.Master" %>
<%@ Register Src="~/Account/OpenAuthProviders.ascx" TagPrefix="uc" TagName="OpenAuthProviders" %>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
In Code-Behind :
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetAllBackgroundImages();
}
if (bgfiles != null)
{
Random r = new Random();
int index = r.Next(bgfiles.Length);
string imgFile = bgfiles[index];
this.Master.ContentBackground = imgFile;
}
In site.Master :
<div id="masterContent" class="container body-content" runat="server">
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
<hr />
site.Master code Behind :
public string ContentBackground
{
get
{
return "";
}
set
{
masterContent.Style.Add("background-image", "url('" + value + "')");
}
}
With the above code, the images are collected in GetAllBackgroundImages();, a image is also selected and this.Master.ContentBackground = imgFile; is also called, but their is no image seen on the Login page.
Any idea where am I going wrong ?? Any help is highly appreciated.
Thanks