ASP.NET Native Coding: Variable Name Not Replaced with Value

I have an ASP.NET page. On page loading, I set the value of public.and to the inline coding part. I am loading CSS, which is a folder with a name that is available in a shared 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

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

But when I start the page, the value <% = VEndorId%> is not replaced by the value in it. But in the body, it is printed correctly. But in the head he does not step. 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" /> 
+4
source share
3 answers

Two parameters:

 <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> 
+7
source

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

+3
source

A similar question and a good answer here .

The solution is to move quotes around inline code into code

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

All Articles