Solved

image ImageUrl

Posted on 2008-10-17
8
999 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Studio npm 1 29
Upgrade code from VS 2010 to VS 2015 7 33
VB.net Filesystem watcher not working 5 37
Adjust the codes 3 31
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

749 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