Solved

image ImageUrl

Posted on 2008-10-17
8
1,007 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

729 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