Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 13th, 2010, 04:48 PM
Registered User
 
Join Date: Apr 2010
Posts: 7
Thanks: 2
Thanked 1 Time in 1 Post
Default Pictures in Photo Album wont display

Imar,

I have been following your steps in building the photoalbum and have managed to successfully implement the photo album functionality completely in a previous demo.

I restarted again, making it into my final year project community website, but for some reason, this time, my images wont load in the listview.
The images are certainly in the database. They get stored physically into the folder ~/ClubPhotos/". The photos ref is stored in the database column "ImageUrl" e.g ~/ClubPhotos/61e1773e-b313-465e-a8e7-5bbd00d55e6f.jpg.
When viewing a photo album using the query string, all my photo data gets displayed except for the image.

I'v built this three times from scratch now, any idea's why the image might not be displayed?

Here's my code from the Page and Code Behind. The database and LINK data classes are exactly the same as in the book.

Cheers,
Robin

<h1>
Manage Photo Album</h1>
<p>
&nbsp;</p>
<asp:ListView ID="ListView1" runat="server" DataKeyNames="Id"
DataSourceID="LinqDataSource1" InsertItemPosition="LastItem"
oniteminserting="ListView1_ItemInserting">
<ItemTemplate>
<li style="">
Description:
<asp:Label ID="DescriptionLabel" runat="server"
Text='<%# Eval("Description") %>' />
<br />
Tooltip:
<asp:Label ID="TooltipLabel" runat="server" Text='<%# Eval("Tooltip") %>' />
<br />

<asp:Image ID="Image1" runat="server" ImageUrl='<% Eval("ImageUrl") %>'/>
<br />

<asp:Button ID="DeleteButton" runat="server" CausesValidation="false" CommandName="Delete"
Text="Delete" />
</li>
</ItemTemplate>

<InsertItemTemplate>
<li style="">Description:
<asp:TextBox ID="DescriptionTextBox" TextMode="MultiLine" runat="server"
Text='<%# Bind("Description") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="DescriptionTextBox" runat="server" ErrorMessage="Please enter a description"></asp:RequiredFieldValidator>
<br />
Tooltip:
<asp:TextBox ID="TooltipTextBox" runat="server" Text='<%# Bind("Tooltip") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="TooltipTextBox" runat="server" ErrorMessage="Please enter a tooltip"></asp:RequiredFieldValidator>

<br />
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Please select a valid .jpg file"></asp:CustomValidator>
<br />

<asp:Button ID="InsertButton" runat="server" CommandName="Insert"
Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Clear" CausesValidation="false" />
</li>
</InsertItemTemplate>
<LayoutTemplate>
<ul class="itemContainer">
<li ID="itemPlaceholder" runat="server" />
</ul>
<div style="">
</div>
</LayoutTemplate>



</asp:ListView>
<p>
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="DataClassesDataContext" EnableDelete="True"
EnableInsert="True" OrderBy="Id desc" TableName="Pictures"
Where="PhotoAlbumId == @PhotoAlbumId"
oninserting="LinqDataSource1_Inserting">
<WhereParameters>
<asp:QueryStringParameter DefaultValue="-1" Name="PhotoAlbumId"
QueryStringField="PhotoAlbumId" Type="Int32" />
</WhereParameters>
</asp:LinqDataSource>
</p>

protected void LinqDataSource1_Inserting(object sender, LinqDataSourceInsertEventArgs e)
{
Picture myPicture = (Picture)e.NewObject;
myPicture.PhotoAlbumId = Convert.ToInt32(Request.QueryString.Get("PhotoAlbu mId"));

FileUpload FileUpload1 = (FileUpload)ListView1.InsertItem.FindControl("File Upload1");
string virtualFolder = "~/ClubPhotos/";
string physicalFolder = Server.MapPath(virtualFolder);
string fileName = Guid.NewGuid().ToString();
string extension = System.IO.Path.GetExtension(FileUpload1.FileName);

FileUpload1.SaveAs(System.IO.Path.Combine(physical Folder, fileName + extension));
myPicture.ImageUrl = virtualFolder + fileName + extension;
}
protected void ListView1_ItemInserting(object sender, ListViewInsertEventArgs e)
{
FileUpload FileUpload1 = (FileUpload)ListView1.InsertItem.FindControl("File Upload1");
if (!FileUpload1.HasFile || !FileUpload1.FileName.ToLower().EndsWith(".jpg"))
{
CustomValidator CustomValidator1 =
(CustomValidator)ListView1.InsertItem.FindControl( "CustomValidator1");
CustomValidator1.IsValid = false;
e.Cancel = true;
}
}
 
Old April 13th, 2010, 05:07 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Robin,

Quote:
I'v built this three times from scratch now, any idea's why the image might not be displayed?
Looks like you made the same mistake three times... ;-)

Compare these two lines of code

<asp:Label ID="TooltipLabel" runat="server" Text='<%# Eval("Tooltip") %>' />
...
<asp:Image ID="Image1" runat="server" ImageUrl='<% Eval("ImageUrl") %>'/>

See the difference? If not: the # sign is missing for the Image....

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
RobinB3 (April 13th, 2010)
 
Old April 13th, 2010, 05:35 PM
Registered User
 
Join Date: Apr 2010
Posts: 7
Thanks: 2
Thanked 1 Time in 1 Post
Default

Lol Omg!

Thanks Alot man. Spent 9 hours solving the problem of a missing # sign today!

Should have taken a break!

Many Thanks,

Robin
 
Old April 13th, 2010, 05:43 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
Should have taken a break!
Ha, yes, or asked for a second pair of eyes earlier.... ;-)

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Photo Album Questions m3ben BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 April 4th, 2007 12:12 PM
paging in photo album xperre BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 April 2nd, 2007 03:32 PM
Error posting photo to photo album abel714 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 10 February 5th, 2007 03:07 AM
Wrox Photo Album Help rsearing BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 6 September 27th, 2006 02:30 PM
Photo Album Menus Tremmorkeep BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 August 15th, 2006 01:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.