社区
C#
帖子详情
ResolveUrl为什么错误?用户控件的html控件路径问题
jianshao810
2009-04-10 10:15:44
<a href='<%= ResolveUrl("~/mp4Down.aspx?did=<%# Eval("DownID")%>") %>'
...全文
54
2
打赏
收藏
ResolveUrl为什么错误?用户控件的html控件路径问题
<a href='<%= ResolveUrl("~/mp4Down.aspx?did=") %>'
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
jianshao810
2009-04-10
打赏
举报
回复
yeah,想到啦。。
<%= ResolveUrl("~/mp4Down.aspx")%>?did=<%# Eval("DownID")%>
这样。
但不想浪费分数。。
随便来人回答一下,把分数给出去。
knifewei
2009-04-10
打赏
举报
回复
这个方法主要是用于“用户控件”中的图片。其它地方也可能,但是本人觉得没有必要,因为~的存在。
<img src='<%= ResolveUrl("~/images/top.gif") %>'>
<td height="20" background='<%= ResolveUrl("~/images/top.gif") %>'></td>
asp.net
用户
控件
中图片及样式
问题
我们在开发网站的大多时候都会用到
用户
控件
,不同功能的aspx文件要放到不同的文件夹,但我们可能要引用同一个
用户
控件
ASP.NET
路径
问题
的解决方法
相对
路径
和绝对
路径
在ASP.NET中可以用~/来解决.
一个ASP.NET的JS管理方案,防止重复引用JS
问题
场景:在自定义
控件
、
用户
控件
、页面、后台代码都会有引用JS的可能,这就会出现混乱或者重复引用的可能。 一个自定义
控件
,用于在ASPX页面中注册JS: public class Script : Control { #region 属性 private string m_Src; /// /// 脚本文件
路径
/// public string Src { get { return m_Src; } set { m_Src = value; } } #endregion /// /// 在
控件
Init的时候将JS
路径
添加到HttpContext.Current.Items["IncludedJavaScript"]中。 /// /// protected override void OnInit(EventArgs e) { base.OnInit(e); if (!string.IsNullOrEmpty(Src)) { string src =
Resolve
Url
(Src); List includedJs = HttpContext.Current.Items["IncludedJavaScript"] as List; if (null == includedJs) { includedJs = new List(); HttpContext.Current.Items["IncludedJavaScript"] = includedJs; } if (!includedJs.Contains(src)) { includedJs.Add(src); } } } } 一个静态类,用于管理JS和在后台代码(cs文件)中注册JS: /// /// Javascript管理器 /// public static class JavaScriptManager { /// /// 包含JS引用。 /// /// public static void Include(params string[] filePaths) { HttpContext context = HttpContext.Current; if (null == context) { throw new Exception("HttpContext为空。"); } System.Web.UI.Page p = context.CurrentHandler as System.Web.UI.Page; if (null == p) { throw new Exception("HttpContext.CurrentHandler不是Page。"); } IList jss = GetIncludedJavaScript(); string
resolve
Url
; foreach (string filePath in filePaths) {
resolve
Url
=p.
Resolve
Url
(filePath); if (!jss.Contains(
resolve
Url
)) { jss.Add(p.
Resolve
Url
(
resolve
Url
)); } } } /// /// 获取已经包含的JS列表 /// /// public static IList GetIncludedJavaScript() { HttpContext context = HttpContext.Current; if (null == context) { throw new Exception("HttpContext为空。"); } IList jss = HttpContext.Current.Items["IncludedJavaScript"] as IList; if (null == jss) { jss = new List(); HttpContext.Current.Items["IncludedJavaScript"] = jss; } return jss; } } 然后写一个基类页面,所有的页面都要继承自这个基类页: public class BasePage : System.Web.UI.Page { public BasePage() { } #region 注册/管理JS引用 /// /// 将引用的JS添加到Page.Head中。 /// private void InitJS() { IList includedJs = JavaScriptManager.JavaScriptManager.GetIncludedJavaScript(); foreach (string jsFilePath in includedJs) { var script = new
Html
GenericControl("script"); script.Attributes["type"] = "text/javascript"; script.Attributes["src"] = jsFilePath; Page.Header.Controls.Add(script); } } /// /// 在呈现之前注册JS /// /// protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); InitJS(); } #endregion } 上面是在OnPreRender中将JS注册到Page.Head中的,所以如果在自定义
控件
中注册JS引用,请在OnPreRender之前引用。 在ASPX页面中注册JS: 在CS页面中注册JS: public partial class _Default : BasePage { protected void Page_Load(object sender, EventArgs e) { JavaScriptManager.JavaScriptManager.Include("~/JS/cs.js", "~/JS/cs.js", "~/JS/cs.js2", "~/JS/cs.js"); } }
ASP.NET中Image
控件
使用详解
本文详细介绍了Image
控件
的使用方法,用实例演示了Image
控件
的用法,希望对大家有所帮助。
asp.net程序在调式和发布之间图片
路径
问题
的解决方法
图片显示的时候,在VS调式时候,地址中有个虚拟文件名,发布后则没有了.所以会有图片显示叉叉的情况.
C#
111,126
社区成员
642,541
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章