image ImageUrl

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

LVL 9
Seven priceFull StackAsked:
Who is Participating?
 
TechTiger007Connect With a Mentor Commented:
try this
Image img = (Image)repeatercontrol.Items[i].FindControl("image1");
img.ImageUrl = "image.jpg";
0
 
the_bachelorCommented:
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
 
TechTiger007Commented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Seven priceFull StackAuthor Commented:
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
 
Seven priceFull StackAuthor Commented:
Its because it is in a repeater thats why. How can i get this to work inside the repeater
0
 
TechTiger007Commented:
dim img as Image = Page.FindControl("image1")  ' you may need to type cast the control to Image here
        img.ImageUrl = "image.jpg";
0
 
Seven priceFull StackAuthor Commented:
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
 
Seven priceFull StackAuthor Commented:
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
All Courses

From novice to tech pro — start learning today.