[英]VB.NET insert a variable from code behind into aspx img src
I'm trying to use a variable from my code behind as the src for an image. 我正在尝试使用后面代码中的变量作为图像的src。 Here is what I have, but it isn't working.
这是我所拥有的,但不起作用。
In my code behind at class level I have: 在我的课程代码中,我有:
Dim maxImage As String = HttpContext.Current.Request.QueryString("imgpath")
And in the aspx: 在aspx中:
<img src="<%# maxImage %>" alt="mylisting" height="275" width="275">
If I just stick the value for maxImage in there the picture shows up, so for some reason the maxImage variable isn't getting inserted? 如果我只是将maxImage的值粘贴在其中,图片就会显示出来,因此由于某种原因,没有插入maxImage变量? I'm guessing my syntax is screwed up somehow and someone with more experience will be able to spot it right away.
我猜我的语法以某种方式搞砸了,有更多经验的人将能够立即发现它。
When I "inspect element" in Chrome I get this: 当我在Chrome中“检查元素”时,得到以下信息:
<img src="" alt="mylisting" height="275" width="275">
Thanks! 谢谢!
Try replacing src="<%# maxImage %>"
with src="<%= maxImage %>"
尝试将
src="<%# maxImage %>"
替换为src="<%= maxImage %>"
Also make sure following line returns image path in correct format- 另外,请确保以下行以正确的格式返回图像路径-
Dim maxImage As String = HttpContext.Current.Request.QueryString("imgpath")
// maxImage should be in format "../imagename.jpg"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.