chaithra manoj
chaithra manoj

Reputation: 63

Getting img src in code behind vb.net

I have two different types of image tags in asp.net as such

<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

  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.

Upvotes: 0

Views: 8321

Answers (1)

Bharadwaj
Bharadwaj

Reputation: 2553

You have to set ImageUrl attribure in <asp:Image /> tag, then you will get it by ADimage1.ImageUrl. Use ImageUrl instead of src, as

<asp:Image ID="ADimage1" height="150" width="150" ImageUrl="../img/ProfilePic.png" runat="server" />

OR

Of you want to use src only then do the following to get src value,

Dim imageurl1 As String = ADimage1.Attributes("src").ToString()

Dim imageurl2 As String = ADimage2.Attributes("src").ToString()

Upvotes: 2

Related Questions