4

I have an ASP.NET page .In the page load i set the value of a public variable.and in the inline coding part,I Am loading a CSS which is the folder with the name which is available in the public variable.My HTML markup is as follows

<%@ Page Language="C#"  EnableEventValidation="false" AutoEventWireup="true" CodeFile="MyPage.aspx.cs"  Theme="GridView" Inherits="GUI.MyPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>MyPage</title>
<link href="../Vendors/<%=vendorName%>/css/style.css" rel="stylesheet" type="text/css" />

</head>
 <body>
<%=vendorName %> <!-- here value is printed correctly -->
 ...
 </body>

and in my code behind

 public partial class MyPage: MyCommonClass
 {
    public string vendorName = "";
     protected void Page_Load(object sender, EventArgs e)
     {
        vendorName = "ACLL";
     }

 }

But when i run the page, the <%=VEndorId%> is not replaced with the value in it .But in the Body,It is printing properly.But in the head it is not coming.I checked the ViewSource and find the source HTML as follows

<link href="../Vendors/&lt;%=vendorName%>/Lib/css/tradein.css" rel="stylesheet" type="text/css" />

3 Answers 3

7

The two options are:

<link href="<%= string.Format("../Vendors/{0}/css/style.css", vendorName) %>" type="text/css" rel="Stylesheet" /> // as Greco stated

and

<style>
  @import url("../Vendors/<%=vendorName%>/css/style.css");
</style>
Sign up to request clarification or add additional context in comments.

Comments

3

Add the runat="server" tag to the link element.

4 Comments

Adding runat Not fixed the problem
<link href="../Vendors/" + <%=vendorName%> + "/css/style.css" rel="stylesheet" type="text/css" />
where did you add runat attribut in the above example ?
<link href="<%= string.Format("../vendors/{0}/Lib/css/tradein.css", vendorName) %>" type="text/css" rel="Stylesheet" is the correct code. No runat=server tag needed my fault! Soz!
0

Similar question and good answer here.

The solution is to move the quotes around the inline code into the code

<link href=<%="'../Vendors/" + vendorName + "/css/style.css'"%> rel="stylesheet"...
               ^                                           ^

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.