Answered by:
How can I get image to display on a page?

Question
-
User1216627406 posted
Can someone please help me understand why images is not displaying on this page?
I have a calendar that displays various events with appropriate pictures.
On the calendar itself, a small image is displayed (this works fine).
Here is the code for that:
<body> <form id="Form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <dc:DataCalendar id="cal1" runat="server" DayField="EventDate" OnVisibleMonthChanged="MonthChange" Height="295px" Width="275px" BorderColor="#EFEFDE" DayNameFormat="Shortest" SelectedDate="2012-11-17"> <DayStyle HorizontalAlign="Left" VerticalAlign="Top" Font-Size="7" Font-Names="Arial" BackColor="white" /> <OtherMonthDayStyle BackColor="white" ForeColor="white" /> <ItemTemplate> <a href='#' OnClick="javascript:window.open('admin/eventDetails.aspx?id=<%# Container.DataItem("EventID") %>','EventsDetail','width=800,height=600;toolbar=no;');" & "> <img alt="" src='images/<%# Container.DataItem("CategoryImage") %>' height="12" width="12" align="absmiddle" border="0" /><br /> <font color='<%# Container.DataItem("CategoryColor") %>'> <%# Container.DataItem("EventTitle") %> </font> </a> </ItemTemplate> <TitleStyle BackColor="#CEDFCE" Font-Bold="True" /> </dc:DataCalendar> </ContentTemplate> </asp:UpdatePanel> </form> </body>
When you on any given date, you are taken to the details page of that part event.
This is where a larger image is supposed to be displayed.
However, the image is not displaying. It is not even showing the little icon when picture is not present.
What am I doing wrong?
Here is that code for the eventDetails page.
Thanks in advance for your assistance.
//VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not IsPostBack Then If (Not (Request.QueryString("id")) Is Nothing) Then Session("apomember") = Request.QueryString("id") End If BindGrid() End If End Sub Private Sub BindGrid() Dim myConnectionstring As String = ConfigurationManager.ConnectionStrings("test").ConnectionString Dim myConn As New SqlConnection(myConnectionstring) myConn.Open() Dim cmd As New SqlCommand("SELECT e.EventID, e.EventTitle, e.EventDescription, e.EventDate, c.CategoryTitle, c.CategoryImage, c.CategoryColor " & "FROM Events e INNER JOIN Categories c ON e.EventCategory = c.CategoryID where c.CategoryID = @apoid ORDER BY e.EventDate", myConn) cmd.Parameters.AddWithValue("@apoid", Session("apomember")) Dim dr As SqlDataReader = cmd.ExecuteReader() If dr.Read() Then txtTitle.Text = dr("EventTitle").ToString() txtTitle.Text = dr("EventDate").ToString() txtDate.Text = dr("EventDescription").ToString() txtDescription.Text = dr("EventTitle").ToString() txtCategory.Text = dr("CategoryImage").ToString() End If myConn.Close() End Sub
//Markup:
<form id="form1" runat="server"> <div> <a href="#" id="logo"><img src="/images/skin1/owerri_logo.jpg" Height="245" Width="322"alt="Owerri Family Union" border="0" title="Owerri Family Union" /></a> Owerri Family Union, Atlanta, GA - USA </div> <hr /> <table> <tr style="margin-top:10px;"> <td><b>Event Title:</b></td> <td><asp:Label id="txtTitle" runat="server"></asp:Label></td> </tr> <tr style="margin-top:10px;"> <td><b>Event Date:</b></td> <td><asp:Label id="txtDate" runat="server"></asp:Label></td> </tr> <tr style="margin-top:10px;"> <td><b>Event Description:</b></td> <td><asp:Label id="txtDescription" runat="server"></asp:Label></td> </tr> <tr style="margin-top:10px;"> <td><b>Category:</b></td> <td> <asp:Image ID="Image1" ImageUrl='/admin/memberPhotos/ & <%# Eval("CategoryImage") %>' runat="server" Height="100" Width="100" /> <asp:Label id="txtCategory" runat="server"></asp:Label></td> </tr> </table> </form>
Wednesday, April 3, 2019 4:23 PM
Answers
-
User475983607 posted
simflex
Hi mgebhard,
You are almost correct.
It says, "bad request"
http://localhost:49836/ofu/admin/memberPhotos/%20&%20%3C%25
Not sure where it is getting the %20&20... from.
The URL is invalid. %20 is an encoded space character in the URL.
<asp:Image ID="Image1" ImageUrl='/admin/memberPhotos/ & <%# Eval("CategoryImage") %>' runat="server" Height="100" Width="100" />
Probably should be?
<asp:Image ID="Image1" ImageUrl='/admin/memberPhotos/<%# Eval("CategoryImage") %>' runat="server" Height="100" Width="100" />
It depends in what Eval("CategoryImage") is... Please use Dev Tools to double check the HTML.
Also this...
<%# Eval("CategoryImage") %>
is a binding expression. Perhaps you are not binding the Image and should set the ImageUrl in the code behind?
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, April 3, 2019 6:29 PM
All replies
-
User475983607 posted
The usual culprit is an invalid image URL. Open the browser's dev tools and go to the Network View. Open the page. 404 errors indicate and invalid image path.
Wednesday, April 3, 2019 4:38 PM -
User1216627406 posted
Hi mgebhard,
You are almost correct.
It says, "bad request"
http://localhost:49836/ofu/admin/memberPhotos/%20&%20%3C%25
Not sure where it is getting the %20&20... from.
Wednesday, April 3, 2019 5:45 PM -
User475983607 posted
simflex
Hi mgebhard,
You are almost correct.
It says, "bad request"
http://localhost:49836/ofu/admin/memberPhotos/%20&%20%3C%25
Not sure where it is getting the %20&20... from.
The URL is invalid. %20 is an encoded space character in the URL.
<asp:Image ID="Image1" ImageUrl='/admin/memberPhotos/ & <%# Eval("CategoryImage") %>' runat="server" Height="100" Width="100" />
Probably should be?
<asp:Image ID="Image1" ImageUrl='/admin/memberPhotos/<%# Eval("CategoryImage") %>' runat="server" Height="100" Width="100" />
It depends in what Eval("CategoryImage") is... Please use Dev Tools to double check the HTML.
Also this...
<%# Eval("CategoryImage") %>
is a binding expression. Perhaps you are not binding the Image and should set the ImageUrl in the code behind?
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, April 3, 2019 6:29 PM -
User1216627406 posted
This seems to have worked.
Image1.ImageUrl = "~/images/" & dr("CategoryImage").ToString()
Thanks for your help.
Wednesday, April 3, 2019 7:54 PM