How ASP.net can dynamically generate URLs in external CSS files

I have been trying to organize my css separately from the *.aspx file. Everything was working fine when the following code was included in the aspx file:

background-image: url('<%=Page.ResolveUrl("~/Themes/Red/Images/Contestant/1.jpg)%>';)

However, now it seems that it is no longer working. Are there any alternative solutions that you know of?

Answer №1

The symbols scriptlet and ~ are specific to aspx files and cannot be used in css.

Replace

background-image: url('<%=Page.ResolveUrl("~/Themes/Red/Images/Contestant/1.jpg)%>';)

With

background-image: url('/Themes/Red/Images/Contestant/1.jpg')

The instructions above assume that the Themes folder is located at the root of your site.

To set the path relative to the css file

background-image: url('Themes/Red/Images/Contestant/1.jpg')

Answer №2

Thanks for the solution, this resolved my issue.

background-image: url(../../images/picture.png)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Lock GridView headers when only scrolling vertically

I am facing an issue with my gridview on an aspx page. The gridview is wider than the page itself, so I want the headers of the gridview to scroll horizontally along with the content, while remaining fixed vertically. Can anyone help me achieve this? I hav ...

Safari displaying incorrect sizing for table nested in inline-flex container

When a <table> is placed within an inline-flex container that has a flex-direction of column, Safari displays the table with a different cross-size compared to Chrome and Firefox. This discrepancy makes me question if Safari's default display fo ...

Tips for stretching the div#header2 across the full length of div#header1

Code: #header1{width:100%;} #header2{ position: absolute; top: 0px; left: 0px; width: 75px; height: 72px; background: url("./image.png"); background-repeat: repeat-x; background-position: -10px -180px; } <div id="heade ...

- bullet point: tabulated

I need to create an unordered list with URLs included and indented, while keeping all lines justified to the left. * line one text text ted more text text text * line two text ted more text text text * line three text ted more text text text ...

CSS Animations are effective in CodePen, but unfortunately, they do not function properly once integrated into an ASP.Net project

I created a unique design on codepen with a background animation, which functions properly there. However, when I integrate it into my ASP.Net Core project, the animation doesn't work as expected. The file references seem correct because the backgroun ...

determining the appropriate text through control discovery

I am encountering an issue where I am unable to assign text to a label by locating a control (textbox) on the previous page. While I am able to locate the control accurately, I am unable to assign the text as Intellisense does not show the "Text" propert ...

The server tag is displaying an error due to incorrect formatting in the hyperlink data-binding section

I'm currently facing an issue with the formatting of my hyperlink. The text part of the hyperlink is working fine, which leads me to believe that the problem lies within the JavaScript. However, I am unable to pinpoint the exact issue. <asp:Templa ...

Tips for creating a responsive container for mobile and smaller devices using Bootstrap 3

Apologies in advance for the lengthy post, but I welcome any suggestions and ideas. Thank you! I'm facing an issue with my layout breaking when the screen size is below 1200px (images and text drop down). I don't mind if they stack vertically on ...

How to align a list item to the right using CSS

I'm having trouble aligning items in a list to the right and adjusting their width based on content length. Unfortunately, I haven't been able to make it work despite multiple attempts. Take a look at my code snippet below: .messages { over ...

Utilizing the after pseudo element for an active selector in CSS

I'm struggling to make an active icon selector work with the after pseudo element. Here is the code I have attempted: <html> <head> <style type="text/css"> .btn{ width:25%; } .name{ background: #fff; color: #000; text-alig ...

The iPhone display scaling issue is causing difficulty viewing the entire website

Currently experiencing difficulties with a page that lacks sufficient content, resulting in a smaller height. As a result, the iPhone is scaling the page and cutting off the full menu bar (960px wide). I attempted to set a minimum height using a media quer ...

Can a different div or HTML element be used in place of the text "Hello World"?

<body onload="myfunction('target')"><div id="target"> "Hey there!" </div></body> Can we replace the text "Hey there!" with another HTML element or div? This is currently a left-to-right marquee text. <script language= ...

Adding a border to the <area> element: A step-by-step guide

Can a border be added around an <area> element? This would be useful for testing an imagemap, however the following code does not achieve the desired effect: area { outline: 1px solid red; border: 1px solid red; } ...

Having Difficulty Positioning Tooltip Beside Input/Label Field

I have created a tooltip using HTML and CSS that appears when hovering over an image. However, I am encountering alignment issues when placing the image next to a textbox/input as it is not inline with the input box, likely due to some absolute positioning ...

Create a new div element in your HTML structure that is not currently defined in your Sass/CSS

Currently, I am developing a React Component that includes a DatePicker feature using PrimeReact's Calendar component. I have a specific requirement to display an arrow on top of the datepicker when it pops up. You can view the desired layout in the ...

Handling Exceptions in Parallel Programming with HttpWebRequest

I am looking to implement parallel programming that includes exception handling. public List<ExcelRecord> GetReport(List<ExcelRecord> records, string type) { foreach (ExcelRecord rec in records) { ...

Combining Bootstrap 3 buttons and input fields into a single row

My collection of buttons and input text box is currently misaligned, as shown in the code below. <div class="col-md-12 pull-right"> <div class="pull-right"> <button type="button" class="btn btn-default btn-xs"> &l ...

When Windows Authentication is enabled, HttpContext.Current.User remains empty

I developed an intranet application in asp.net using windows authentication several years ago with VS 2005. At that time, the windows authentication was functioning perfectly. In my web.config file, I have configured the authentication mode to "Windows" an ...

What is the best way to create a scrollable tbody in an HTML table using React?

In my current project, I am using React, Node, Express, and Postgres to fetch data from a database. The issue I'm facing involves creating a scrollable table within a div that spans the entire screen width. Initially, I had to apply display: block to ...

Encasing extracted content in <p> tags

On my Wordpress Site, I have extracted images and text separately to use in different sections of my single.php file. Utilizing HTML within the Bootstrap 3 framework: <div class="row"> <div class="col-md-12"> <?php ...