RESOLVEURL问题在母版页 [英] ResolveUrl Problem in Master Page

查看:192
本文介绍了RESOLVEURL问题在母版页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,

我知道这很奇怪,但是当我把这个code之间<头=服务器>< /头> 在master.page ,这是怎么渲染成:

 <链路ID =ctl00_Link1的rel =快捷方式图标的href =../% 3C%25%20ResolveUrl(22%〜/资源/图片/共享/杂项/favicon.ico%22);%20%25%3ETYPE =图像/ X-图标/>

它不会看到的东西asp.net需要照顾。

这是原来的code:

 <链路ID =链接1的rel =快捷方式图标的href ='<%= RESOLVEURL(〜/资源/图片/共享/其它/ favicon.ico的 )%GT;'类型=图像/ X-图标=服务器/>

基本上Asp.Net不照顾低于code,并呈现为一个普通的HTML。

如何克服这个问题?

在此先感谢...

修改和解决

好人,也没有办法这样做。我终于想通了,因为RESOLVEURL或ResolveClientUrl只工作了这些如下:

  @import'<%= RESOLVEURL(〜/资源/风格/ MainMaster / MainDesign.css)%>';
<脚本的src ='资源/脚本/库/ jQuery的-1.4.2.js类型=文/ JavaScript的< / SCRIPT>

这是链接太乏味了,所以你需要把链接元素在体内的标签,如:

 <身体GT;
    <链路ID =iconOne的rel =快捷方式图标类型=图像/ X-图标的href =资源/图片/共享/其它/ favicon.ico的/>
    <链路ID =iconTwo的rel =图标的href ='资源/图片/共享/其它/ favicon.ico的类型=图像/ ICO/>
< /身体GT;


解决方案

所以,你遇到了你的第一个问题的原因是因为该链接标记有 =服务器这告诉asp.net把它当作一台服务器控制,而不是文字。由于它的服务器控制,您的小脚本标签(<%=%> )是不是真的做任何事情,因为它的服务器控件属性它是把它当作字面文字。

有两种方法来处理它。首先是 ClientScriptManager 注册一个启动脚本。这将使你的链接标签的身体,这是微软说,你应该做的方式,但从美学是不是很好进去。另一种选择是做这样的事情在你的Page_Load

  VAR链接=新HtmlGenericControl(链接);
link.Attributes.Add(相对,快捷方式图标);
link.Attributes.Add(src用户,RESOLVEURL(〜/资源/图片/共享/其它/的favicon.ico));
link.Attributes.Add(型,图像/ X-图标);Header.Controls.Add(链接);

这编程建立了一个控制按钮,然后将其添加到控件集合在头上,这会使你想在头标记的到底是什么。这个问题是,它更多的工作,它的更好,以避免在后面的水平code。与控制集合胡闹,如果你能逃脱它。

Okay,

I know it is weird but when I put this code between <head runat="server"></head> in master.page, this is how it renders into:

 <link id="ctl00_Link1" rel="shortcut icon" href="../%3C%25%20ResolveUrl(%22~/Resources/Pictures/Shared/Misc/favicon.ico%22);%20%25%3E" type="image/x-icon" />

It doesn't see something asp.net needs to take care of.

This is the original code :

<link id="Link1" rel="shortcut icon" href='<%=ResolveUrl("~/Resources/Pictures/Shared/Misc/favicon.ico") %>' type="image/x-icon" runat="server" />

Basically Asp.Net doesn't take care of the code below and renders as a normal html.

How can I get over this problem?

Thanks in advance...

Edit and Resolved

Okay people, there is no way for doing this. I've finally figured out because ResolveUrl or ResolveClientUrl is only working for these below :

@import '<%= ResolveUrl("~/Resources/Styles/MainMaster/MainDesign.css") %>';
<script src='Resources/Scripts/Libraries/jquery-1.4.2.js' type="text/javascript"</script>

it is too literal for link so you need to put link elements in body tag like :

<body>
    <link id="iconOne" rel="shortcut icon" type="image/x-icon" href="Resources/Pictures/Shared/Misc/favicon.ico"/>
    <link id="iconTwo" rel="icon" href='Resources/Pictures/Shared/Misc/favicon.ico' type="image/ico" />
</body>

解决方案

So, the reason you ran into your first issue was because the link tag had runat="server" This tells asp.net to treat it as a server control, rather then a literal. Because its a server control, your scriptlet tag (<%= %>) isn't really doing anything, since its a server control property it is treating it as literal text.

There are two ways to handle it. First is to ClientScriptManager to register a startup script. This will put your link tag inside the body, which is the way microsoft says you should do it, but aesthetically isn't that nice. The other option is to do something like this in your Page_Load

var link = new HtmlGenericControl("link");
link.Attributes.Add("rel", "shortcut icon");
link.Attributes.Add("src", ResolveUrl("~/Resources/Pictures/Shared/Misc/favicon.ico"));
link.Attributes.Add("type", "image/x-icon");

Header.Controls.Add(link);

This builds out a control programatically, then adds it to the controls collection on the head, which will render as what you want at the end of the head tag. Problem with this is that its a bit more work, and its better to avoid monkeying with control collections at the code behind level if you can get away with it.

这篇关于RESOLVEURL问题在母版页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆