I'm trying to set a background-image for a blog header in ASP web forms. I'm not sure what the best practice is, but the image is set dynamically, and I have a <div>
element with the id="blogHeaderImage"
and runat="server"
. In the code-behind I'm trying to set the image with
blogHeaderImage.Attributes.Add("style", "display: none");
but blogHeaderImage
gives the error "The name "blogHeaderImage" does not exist in this context".
What am I missing here? Thank you in advanced.
I've tried the approved answers in: How do you modify style in the code behind file for divs in ASP.net? and Find div tag from code behind
But this:
<div id="blogHeaderImage" runat="server" class="blog-header-image cover" style='background-position: 30% 100%'>
along with this:
blogHeaderImage.Style.Add("background-image", "url(" + thisPage.HeaderImg + ")");
Doesn't work (error message above).
I would like to use thisPage.HeaderImg
(a url) as the background image.