用户控件和母版页之间不一致
我正在使用带有母版页和用户控件的 asp.NET。
在 MasterPage 中:
这样做
<link href='<%=ResolveUrl("~/path/file.css")%>' rel="stylesheet" type="text/css" />
将不起作用,并且 css 将不会加载 但
执行
<link runat="server" href='~/path/file.css' rel="stylesheet" type="text/css" />
将起作用,并且 css 将加载
在用户控制中:
执行
<link runat="server" href='~/path/file.css' rel="stylesheet" type="text/css" />
将不起作用,并且 css 将不会加载
但是
执行
<link href='<%=ResolveUrl("~/path/file.css")%>' rel="stylesheet" type="text/css" />
将起作用,并且 css 将加载
在母版页中 ResolveUrl 不起作用并且 runat= “服务器”在用户控制中起作用,情况恰恰相反。如果有人会检查这个,也许我会很感激。如果是这种情况,那么造成这种不一致的原因是什么?
I am using asp.NET with masterpages and usercontrols.
In MasterPage:
Doing
<link href='<%=ResolveUrl("~/path/file.css")%>' rel="stylesheet" type="text/css" />
will not work and the css will not load
BUT
Doing
<link runat="server" href='~/path/file.css' rel="stylesheet" type="text/css" />
will work and the css will load
In User Control:
Doing
<link runat="server" href='~/path/file.css' rel="stylesheet" type="text/css" />
will not work and the css will not load
BUT
Doing
<link href='<%=ResolveUrl("~/path/file.css")%>' rel="stylesheet" type="text/css" />
will work and the css will load
In master page ResolveUrl doesn't work and runat="server" works where in user control the opposite is the true. Maybe I worng and I appriciate if someone will check this. If this is the situation, what is the reason for this inconsistency?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在此处阅读详细信息。
简而言之,“~”字符只能在服务器上使用
You can read here in details what is going on.
In short is so the '~' character is only for use at the server
好的,我明白了。
在其中一种情况下,我有
标签。因为 runat="server",所以 ResolveUrl 不是充当服务器方法,而是一个简单的文本。这就是为什么 ResolveUrl 没有说 - 我在 head 标签中有 runat="server" 。
Ok, I got it.
In one of the cases I had
<head runat="server">
tag. Because the runat="server", the ResolveUrl is not act as a server method but a simple text. That is why ResolveUrl didn't word - I had runat="server" in the head tag.