Solved

image ImageUrl

Posted on 2008-10-17
8
982 Views
Last Modified: 2012-05-05
Dim Image1 As New Image
        Image1.ID = "Image1"
        Image1.ImageUrl = "~\phonelist\Photos\camera.gif"
        Image1.Visible = True

            <asp:Image ID="Image1"  Visible="True" runat="server" />


I trying to do this in VB but the src keep coming up blank. I could do this on the front end but I need to make this dynamic for other reason. But why nothing appears in the src, that is a mystery to me.
<img id="ctl00_Attendance1_Repeater1_ctl00_Image1" src="" style="border-width:0px;" />

Open in new window

0
Comment
Question by:sevensnake77
  • 4
  • 3
8 Comments
 
LVL 7

Expert Comment

by:the_bachelor
ID: 22741617
First of all if the image is already defined on your page (you already have: <asp:Image ID="Image1"  Visible="True" runat="server" /> )
Why are you declaring a new image in the code behind? (Dim Image1 as new Image)

You could just do Me.Image1.ImageUrl = "~\phonelist\Photos\camera.gif"
Now it seem like your image control is in a repeater so you might wanna watch out for how you handle that...
0
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22741754
Are you adding the control to the page
below code works good for me

Image img = new Image();
        img.ImageUrl = "file.jpg";
        Page.Controls.Add(img);
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 22741881
Object reference not set to an instance of an object.Object reference not set to an instance of an object.  Description:  An unhandled exception occurred during the execution of the current web  request. Please review the stack trace for more information about the error and  where it originated in the code.

Exception Details:  System.NullReferenceException: Object reference not set to an instance of an  object.

Source Error:

    Line 18:  Line 19:  Line 20:         Me.Image1.ImageUrl = "~\phonelist\Photos\camera.gif" Line 21:         Image1.Visible = True Line 22:         Page.Controls.Add(Image1)

Me.Image1.ImageUrl = "~\phonelist\Photos\camera.gif"

Open in new window

0
 
LVL 9

Author Comment

by:sevensnake77
ID: 22741964
Its because it is in a repeater thats why. How can i get this to work inside the repeater
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 13

Expert Comment

by:TechTiger007
ID: 22742487
dim img as Image = Page.FindControl("image1")  ' you may need to type cast the control to Image here
        img.ImageUrl = "image.jpg";
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 22742596
Nope still Object reference not set to an instance of an object.Object reference not set to an instance of an object.  Description:  An unhandled exception occurred during the execution of the current web  request. Please review the stack trace for more information about the error and  where it originated in the code.
only when its in the repeater.
0
 
LVL 13

Accepted Solution

by:
TechTiger007 earned 500 total points
ID: 22742718
try this
Image img = (Image)repeatercontrol.Items[i].FindControl("image1");
img.ImageUrl = "image.jpg";
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 22742837
Sorry nothing either if you create a repeater and test it you will see.
Dim img As Image = Page.FindControl("image1")  ' you may need to type cast the control to Image here
        img.ImageUrl = "~\phonelist\Photos\camera.gif"

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now