ASP.NET 中图像的 ImgUrl 属性的预处理器指令存在问题
我想解析 QueryString 并将 ID 值放入 ImgUrl 路径,我正在尝试这段代码:
<asp:Image ID="imgImageNormal" runat="server" ImageUrl='<%# string.Format("ImageHandler.ashx?ID={0}",Request.QueryString["ID"].ToString()) %>'/>
但生成的结果是无。我没有收到任何错误消息,但查看页面源代码后,这是图像的输出:
<img id="ctl00_ContentPlaceHolder1_imgImageNormal" src="" style="border-width:0px;" />
我做错了什么?
I would like to parse QueryString and put the ID value to the ImgUrl path, I am trying this code:
<asp:Image ID="imgImageNormal" runat="server" ImageUrl='<%# string.Format("ImageHandler.ashx?ID={0}",Request.QueryString["ID"].ToString()) %>'/>
But the produced result is none. I am not getting any error message but after viewing the source of the page, this is the output for the image:
<img id="ctl00_ContentPlaceHolder1_imgImageNormal" src="" style="border-width:0px;" />
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是在绑定的范围内吗?如果不是,
<%#...%>
语法将不起作用。此代码有效:注意设置
runat="server"
或将 src 属性括在引号中将导致此失败。尽管上述方法有效,但您可能最好只从 page_load 事件的代码隐藏中设置 asp:image 控件的 imageurl 属性。有关在何处使用 ASP.NET 内联标记的参考,请查看此站点:
http ://naspinski.net/post/inline-aspnet-tags-sorting-them-all-out-(3c25242c-3c253d2c-3c252c-3c252c-etc).aspx
Is this within the context of binding? If not, the
<%#...%>
syntax will not work. This code works:Note setting
runat="server"
or enclosing the src attributes in quotes will cause this to fail. Although the above works, you would probably be better off just setting the imageurl property of an asp:image control from the codebehind on the page_load event.For reference on where to use asp.net inline tags check out this site:
http://naspinski.net/post/inline-aspnet-tags-sorting-them-all-out-(3c25242c-3c253d2c-3c252c-3c252c-etc).aspx