I'm trying to force a value into the linked .js and .css files. It works fine on my js files but not on my css. Example code:
<script src="/Scripts/ExampleJSFile.js?v=<%= version %>"></script>
<link href="/Styles/ExampleCSSFile.css?v=<%= version %>" rel="stylesheet" >
Which is giving the following result:
<script src="/Scripts/ExampleJSFile.js?v=5.0.0.1"></script>
<link href="Styles/ExampleCSSFile.css?v=<%= version %>" rel="stylesheet">
I am using asp.net c# (WebForms) as my code behind framework.
Thanks
Event binding and dynamic codes run only on server side controls and code snippet that can be accessed by .net.
By default asp.net process script src tag and replace value for you, But when it come to somethings like css link or favicons, the compiler dose not process your code and just send it to client.
You must place things like these into server container elements like placeholder.
I always use code like this to solve it:
<asp:PlaceHolder runat="server" ID="StylesPlaceHolder">
<link href="/Styles/ExampleCSSFile.css?v=<%= version %>" rel="stylesheet" >
</asp:PlaceHolder>
It will result in something like this:
<link href="/Styles/ExampleCSSFile.css?v=5.0.0.1" rel="stylesheet" >
Related
As follows in my code i have referenced my css from html
<link rel="stylesheet" href="../static/css/eja.css" type="text/css" media="all" />
and i have this structure
Application class doesnt have anything extra, just standard generated application class.
Seems i need to write /css/eja.css even if it is not existing in this folder.
Cause css resources loaded to /css/** and not to other path.
I've been trying to connect html with the CSS.
I've checked that:
The stylesheet path of the css is correct, and it is: css2/css2.css
The <link rel="stylesheet" type="text/css" href="css2/css2.css" /> code is well written and I think it is.
I also tried to try several code editors in case it was a preview problem, I've already tried Atom and brackets and the two do not show that the CSS gets connected.
HTML code :
The html close tag is written too at the bottom.
CSS
here is where the html and CSS file is placed
As you have mentioned in your statement that css files is css/css2.css
so it means you should link css file by this code.
<link rel="stylesheet" type="text/css" href="css/css2.css" />
You added css2 instead of css as folder name
This code will 100% work, Just make sure your HTML file and CSS2 folder need to be on same level (in same folder).
otherwise this CSS file not link to your HTML.
Hi I am facing a problem including js/css even image src in JSP files.
When my application starts with any context say abc ex. http://localhost:8080/abc and browser on a url ex http://localhost:8080/abc/reports/userCount and in that JSP i am including css as
<link rel="stylesheet" type="text/css" href="resources/thirdparty/css/jquery-ui.smoothness.min.css">
a 404 error is shown in browser console and the URL to download css is formed as
http://localhost:8080/abc/reports/resources/thirdparty/css/jquery-ui.smoothness.min.css
But when I am on on a page with URL like
http://localhost:8080/abc/createBadgeStep2
the same include to css works fine because url to download css is created fine.
http://localhost:8080/abc/resources/thirdparty/css/jquery-ui.smoothness.min.css
I can see clearly here that second slash after Context in the URL is creating problem. But can't figure out how to fix it. The problem goes for js and images too.
Any help will be highly appreciated.
Import your stylesheet as
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/resources/thirdparty/css/jquery-ui.min.css">
If you are importing several resources down the page, better set the context path in a page-scoped variable using the <c:set> JSTL tag.
<c:set var="ctxPath" value="${pageContext.request.contextPath}" />
Then use the variable in your href attribute.
<link rel="stylesheet" type="text/css" href="${ctxPath}/resources/..." />
You would also need to import the JSTL tag library to use the <c:set> tag.
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
I'm trying to include a stylesheet in one of my aspx pages. The stylesheet is in the directory /Dir1/style.css (relative to the project root). I'm trying to get it to resolve in a page that's at the path: /Dir1/MyPage.aspx. I'm aware that I could just include the stylesheet in the header, since it's in the same directory, but I'm trying to use the runat="server" tag so that it would be easier to move the page later if needed.
This is the line I'm using:
<link runat="server" rel="stylesheet" href="~/Dir1/style.css" type="text/css" media="all"/>
Everything I read indicate this is supposed to work, but no matter what I do, I get a 404 in the browser for that stylesheet. The runat attribute doesn't seem to be doing anything - the path the browser is trying to fetch ends up being: http://localhost:7205/Dir1/~/Dir1/style.css. What am I doing wrong?
try this:
<link runat="server" rel="stylesheet" href="<%= Page.ResolveUrl("~/Dir1/style.css") %>" type="text/css" media="all"/>
And you should not need the runat=server
I'm having trouble setting up the href of my CSS.
My projected is located at
www.mysite.com/myproject/
My css is located at
www.mysite.com/myproject/styles/css/css.css
When I'm at www.mysite.com/myproject/, everything works fine. but when i go into a directory, (www.mysite.com/myproject/dir1/) the css is no longer found. My guess is that it's looking for the css at www.mysite.com/myproject/dir1/styles/css/css.css.
I'm currently using master pages. How do I properly reference the css?
Edit:
This is currently how i reference my CSS.
link rel="stylesheet" type="text/css" href="/content/css/bootmetro.css"
but it doesn't work properly because the project is not located at the root (www.mysite.com). it is located at www.mysite.com/myproject/. So having the "/" causes the css not to load at all.
Set the css path like this, starting slash means root of the site.
/styles/css/css.css
Have you tried:
link rel="stylesheet" type="text/css" href="../styles/css/bootmetro.css"
Assuming you are using ASP.NET, try like this:
<link rel="Stylesheet" type="text/css" href="<%= ResolveURL("~/content/css/bootmetro.css")%>" />