Link to home
Start Free TrialLog in
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

 


Avatar of pradyahuja
pradyahuja
Flag of Australia image


<link href="<%= Page.ResolveClientUrl("~") %>script/css/test.css" type="text/css" rel="stylesheet">
Avatar of techques
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.

change the code to
<head runat="server">
<title></title>
<script></script>
<link href="~/script/css/test.css" type="text/css" rel="stylesheet" />
</head>
ASKER CERTIFIED SOLUTION
Avatar of techques
techques

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial