Avatar of techques
techques
 asked on

How C# ResolveClientUrl in Masterpage

There is a masterpage in asp.net which I want to use
<link href="<%= this.ResolveClientUrl("~/script/css/test.css") %>" type="text/css" rel="stylesheet">

When I see the view source in IE, it becomes empty:
<link href="" type="text/css" rel="stylesheet">

I also tried <%= Request.ApplicationPath %> + /script/css/test.css
It only showed /script/css/test.css

How should I use ResolveClientUrl in Masterpage? as the current relative path needs ../../script/css/test.css which work. Otherwise, it does not work

 


.NET ProgrammingASP.NETC#

Avatar of undefined
Last Comment
techques

8/22/2022 - Mon
pradyahuja


<link href="<%= Page.ResolveClientUrl("~") %>script/css/test.css" type="text/css" rel="stylesheet">
techques

ASKER
It does not work, it shows

href="script/css/test.css"

but not href="../../script/css/test.css"

The aspx page placed in
/product/info/index.aspx

it calls the master page which in root directory

The header html code saved in a html file.
<head runat="server">
<title></title>
<script></script>
<link href="<%= Page.ResolveClientUrl("~") %>script/css/test.css" type="text/css" rel="stylesheet" />
</head>
and located in
/product/info/header.html

I use Server.MapPath to load the html in index.aspx.cs Page_Load

ParseControl and add to the PlaceHolder in masterpage.

All code in html can display properly.

However, only Page.ResolveClientUrl("~") become empty.

If I put ResolveClientUrl in index.aspx.cs, it can show ../../script/css/test.css

If I put Page.ResolveClientUrl in masterpage, it can also show
../../script/css/test.css

However, when I parse the header.html to the placeholder controller, it becomes empty.

How should I fix it?

I tried many methods to do it but still failed.

pradyahuja

change the code to
<head runat="server">
<title></title>
<script></script>
<link href="~/script/css/test.css" type="text/css" rel="stylesheet" />
</head>
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
techques

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.