2009年12月18日 星期五

在 master page 中引用 image

在 master page 中使用資源,如 image, js 等,需要更多的技巧。

舉例來說,在 aspx 中引用 image 是相當簡單的事
<td background=”./imgs/a.jpg”>
只要該頁面與 a.jpg 的相對位置是固定的即可。

而 master page 是要給每個頁面 (aspx) 來套用版型的,在 master page 中引用 image 會面臨相對位置不固定的問題。

解決方法是:
<td background='<%=ResolveUrl("~/imgs/a.jpg") %>' >

如果要使用在 css block 時,可使用如下的寫法
<style>
.def02 {
background-image: url(<%= Page.ResolveUrl("~/imgs/a.jpg") %>);
}
</style>

沒有留言:

Share with Facebook