Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

image ImageUrl

Posted on 2008-10-17
8
Medium Priority
?
1,033 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:Seven price
[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:Seven price
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 9

Author Comment

by:Seven price
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:Seven price
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 1500 total points
ID: 22742718
try this
Image img = (Image)repeatercontrol.Items[i].FindControl("image1");
img.ImageUrl = "image.jpg";
0
 
LVL 9

Author Comment

by:Seven price
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

Independent Software Vendors: 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

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…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

722 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