Link to home
Start Free TrialLog in
Avatar of techques

asked on

How C# ResolveClientUrl in Masterpage

There is a masterpage in 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
Flag of Australia image

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


It does not work, it shows


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

The aspx page placed in

it calls the master page which in root directory

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

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

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

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