ASP.NET 中图像的 ImgUrl 属性的预处理器指令存在问题

发布于 2024-10-03 03:39:06 字数 420 浏览 1 评论 0原文

我想解析 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇柔作态 2024-10-10 03:39:06

这是在绑定的范围内吗?如果不是,<%#...%> 语法将不起作用。此代码有效:

<img ID="imgImageNormal" src=<%=string.Format("ImageHandler.ashx?ID={0}",Request.QueryString["ID"].ToString())%> />

注意设置 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:

<img ID="imgImageNormal" src=<%=string.Format("ImageHandler.ashx?ID={0}",Request.QueryString["ID"].ToString())%> />

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文