0

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.

Patrick
  • 17
  • 2
  • 5
  • this is duplicate question: https://stackoverflow.com/questions/5066031/dynamic-background-image-on-body-asp-net. – Mr doubt Apr 05 '19 at 12:39

1 Answers1

-1

You can use OnInit(EventArgs e) event method to get image dynamic into body. Please refer below link.

Dynamic background-image on body (ASP.NET)

Mr doubt
  • 51
  • 1
  • 10
  • 42