在 vb.net 后面的代码中获取 img src
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23246316/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting img src in code behind vb.net
提问by chaithra manoj
I have two different types of image tags in asp.net as such
我在 asp.net 中有两种不同类型的图像标签
<asp:Image ID="ADimage1" height="150" width="150" src="../img/ProfilePic.png"
runat="server" />
'binary data as image has been set
'已将二进制数据设置为图像
<asp:Image ID="ADimage2" height="150" width="150" src="data:image/jpeg;base64,iVBORw0KGg" runat="server" />
and a vb.net button click as such
和一个 vb.net 按钮点击这样
Protected Sub btnUploadClick(sender As Object, e As System.EventArgs) Handles btnUpload.Click
'not able to get image url
Dim imageurl1 As String =ADimage1.ImageUrl
'not able to get image url
Dim imageurl2 As String =ADimage2.ImageUrl
EndSub
I am not able to get image url in the backend. it is vb.net web application . Please help.
我无法在后端获取图像 url。它是 vb.net 网络应用程序。请帮忙。
回答by Bharadwaj
You have to set ImageUrlattribure in <asp:Image />tag, then you will get it by ADimage1.ImageUrl. Use ImageUrlinstead of src, as
您必须ImageUrl在<asp:Image />标签中设置属性,然后您将通过ADimage1.ImageUrl. 使用ImageUrl代替src,作为
<asp:Image ID="ADimage1" height="150" width="150" ImageUrl="../img/ProfilePic.png" runat="server" />
OR
或者
Of you want to use srconly then do the following to get srcvalue,
你想使用src只有做以下才能获得src价值,
Dim imageurl1 As String = ADimage1.Attributes("src").ToString()
Dim imageurl2 As String = ADimage2.Attributes("src").ToString()

