开发者

Page markup maintainability

where js folder is under the root.

if u put this JS ref in common\SomeControl.ascx, it will work fine if SomeControl is placed on开发者_StackOverflow中文版 ~/SomePage.aspx because SomePage is under the website root.

How to put JS ref in SomeControl and allow it to be placed at any path on the website without losing the JS ref.

Thanks


Write this method in your asp.net page code-behind.

code-behind

/// <summary>
/// Gets full page url.
/// </summary>
/// <param name="url">Partial url.</param>
/// <returns>page url.</returns>
public string ResolveResourceUrl(string url)
{
    return String.Format("{0}/{1}", TemplateSourceDirectory, url);
}

page mark-up, use it anywhere on the page

<link href="<%= ResolveResourceUrl("css/aspnet.css") %>" rel="stylesheet" type="text/css" />

you can have a common PageBase class in your application and define the method in the page-base class and make it available to all pages in your application.


you can directly use the path like /js/somejs.js. With this the files is searched from the root. Not sure if this is your problem but hope that helped.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜