 |
BOOK: Beginning ASP.NET 4 : in C# and VB
 | This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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
|
|
|
|
|

July 24th, 2012, 06:11 PM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Images does not shows up / Ch 14 photoalbum
Imar,
I worked through Ch 14 where we suppose to insert albums with images. I checked folder GigPics, files getting inserted with newly generated GUIDs but,
on the page images does not appear, only frame of empty image control. Any idea? Thanks, Alex
|
|

July 24th, 2012, 06:38 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi Alex,
Take a look in the Pictures table in the database. Do you see the image URLs there?
If that doesn't shed any light, can you post you markup as well as the final HTML in the browser?
Cheers,
Imar
|
|

July 24th, 2012, 07:18 PM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Another problem
Thanks Imar, I found problem, left off "/" after "/GigPics".
Another problem, not single album shows up in ManagePhotoAlbum page. I check database everything there. Below is a markup, I ran through Compare utility against your and can not find any difference
<%@ Page Title="Manage Photo Album" Language="C#" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="true" CodeFile="ManagePhotoAlbum.aspx.cs" Inherits="_ManagePhotoAlbum" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<asp:ListView ID="ListView1" runat="server" DataKeyNames="Id"
DataSourceID="EntityDataSource1" InsertItemPosition="LastItem"
oniteminserting="ListView1_ItemInserting">
<InsertItemTemplate>
<li style="">
Description:
<asp:RequiredFieldValidator ID="reqDesc" ControlToValidate="DescriptionTextBox" runat="server"
ErrorMessage="Enter description" />
<asp:TextBox ID="DescriptionTextBox" runat="server"
Text='<%# Bind("Description") %>' />
<br />ToolTip:
<asp:RequiredFieldValidator ID="reqTooltip" ControlToValidate="ToolTipTextBox"
runat="server" ErrorMessage="Enter a tool tip" />
<asp:TextBox ID="ToolTipTextBox" runat="server" Text='<%# Bind("ToolTip") %>' />
<asp:FileUpload ID="FileUpload1" runat="server" />
<br />
<asp:CustomValidator ID="cusValImage" runat="server"
ErrorMessage="Select a valid .jpg file" />
<asp:Button ID="InsertButton" runat="server" CommandName="Insert"
Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Clear" CausesValidation="false" />
</li>
</InsertItemTemplate>
<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="ImageUrl" runat="server" ImageUrl='<%# Eval("ImageUrl") %>' />
<br />
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" CausesValidation="true"/>
</li>
</ItemTemplate>
<LayoutTemplate>
<ul class="ItemContainer">
<li runat="server" id="itemPlaceholder" />
</ul>
</LayoutTemplate>
</asp:ListView>
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=PlanetWroxEntities"
DefaultContainerName="PlanetWroxEntities" EnableDelete="True"
EnableFlattening="False" EnableInsert="True" EntitySetName="Pictures"
Where="it.photoAlbumId = @photoAlbumId"
oninserting="EntityDataSource1_Inserting">
<WhereParameters>
<asp:QueryStringParameter Name="PhotoAlbumId" QueryStringField="PhotoAlbumId"
Type="Int32" />
</WhereParameters>
</asp:EntityDataSource>
</asp:Content>
|
|

July 25th, 2012, 03:13 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Take a look at this:
Code:
QueryStringField="PhotoAlbumId"
Are you sure you're passing the correct query string parameter from the new album page? Can you post the code for that page?
Imar
|
|

July 25th, 2012, 11:09 AM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Code
From NewPhotoAlbum page
protected void EntityDataSource1_Inserted(object sender, EntityDataSourceChangedEventArgs e)
{
Photoalbum newPhotoAlbum = (Photoalbum)e.Entity;
Response.Redirect(string.Format("ManagePhotoAlbum. aspx?PhotoAlbumId={0}",
newPhotoAlbum.Id.ToString()));
}
From ManagePhotoAlbum page
protected void EntityDataSource1_Inserting(object sender, EntityDataSourceChangingEventArgs e)
{
int photoAlbumId = Convert.ToInt32(Request.QueryString.Get("PhotoAlbu mId"));
Picture myPicture = (Picture)e.Entity;
myPicture.PhotoalbumId = photoAlbumId;
FileUpload FileUpload1 =
(FileUpload)ListView1.InsertItem.FindControl("File Upload1");
string virtualFolder = "~/GigPics/";
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 cusValImage =
(CustomValidator)ListView1.InsertItem.FindControl( "cusValImage");
cusValImage.IsValid = false;
e.Cancel = true;
}
}
|
|

July 25th, 2012, 11:29 AM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Imar,
I just want to point out, if I can not see all the items probably something wrong with listview binding, code have nothing to do with it, from what I see, code only relevant to inserting new album functionality and no matter what, am I inserting or not, listview should be populated from database. Am I wrong? Thanks, Alex
|
|

July 25th, 2012, 11:55 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I am not sure I understand what you're saying. Can you elaborate?
If you see pictures in the database and not in ManageAlbum, then yes, something is wrong with the binding. Can you sjhow the Markup for the page as well?
Imar
|
|

July 25th, 2012, 12:01 PM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
ManagePhotoAlbum page does not show any album at all, looks like ItemTemplate for ListView is not working after changes I made in relation to bringing pictures. Below is the markup for this page. Thank you
Code:
<%@ Page Title="Manage Photo Album" Language="C#" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="true" CodeFile="ManagePhotoAlbum.aspx.cs" Inherits="_ManagePhotoAlbum" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<asp:ListView ID="ListView1" runat="server" DataKeyNames="Id"
DataSourceID="EntityDataSource1" InsertItemPosition="LastItem"
oniteminserting="ListView1_ItemInserting">
<InsertItemTemplate>
<li style="">
Description:
<asp:RequiredFieldValidator ID="reqDesc" ControlToValidate="DescriptionTextBox" runat="server"
ErrorMessage="Enter description" />
<asp:TextBox ID="DescriptionTextBox" runat="server"
Text='<%# Bind("Description") %>' />
<br />ToolTip:
<asp:RequiredFieldValidator ID="reqTooltip" ControlToValidate="ToolTipTextBox"
runat="server" ErrorMessage="Enter a tool tip" />
<asp:TextBox ID="ToolTipTextBox" runat="server" Text='<%# Bind("ToolTip") %>' />
<asp:FileUpload ID="FileUpload1" runat="server" />
<br />
<asp:CustomValidator ID="cusValImage" runat="server"
ErrorMessage="Select a valid .jpg file" />
<asp:Button ID="InsertButton" runat="server" CommandName="Insert"
Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Clear" CausesValidation="false" />
</li>
</InsertItemTemplate>
<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="ImageUrl" runat="server" ImageUrl='<%# Eval("ImageUrl") %>' />
<br />
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" CausesValidation="true"/>
</li>
</ItemTemplate>
<LayoutTemplate>
<ul class="ItemContainer">
<li runat="server" id="itemPlaceholder" />
</ul>
</LayoutTemplate>
</asp:ListView>
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=PlanetWroxEntities"
DefaultContainerName="PlanetWroxEntities" EnableDelete="True"
EnableFlattening="False" EnableInsert="True" EntitySetName="Pictures"
Where="it.photoAlbumId = @photoAlbumId"
oninserting="EntityDataSource1_Inserting">
<WhereParameters>
<asp:QueryStringParameter Name="PhotoAlbumId" QueryStringField="PhotoAlbumId"
Type="Int32" />
</WhereParameters>
</asp:EntityDataSource>
</asp:Content>
|
|

July 26th, 2012, 03:39 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
I copied and pasted your code in my Planet Wrox project and it all worked fine (had to rename Photoalbum to PhotoAlbum to match my table / EF name, but that was it).
How are you browsing to this page? Do you go through NewAlbum.aspx first? Also, when you look in the database, do you see the correct PhotoAlbumIds for the pictures in the Pictures table?
Imar
|
|

July 26th, 2012, 10:30 AM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Imar,
I checked both tables, Photoalbum and Picture, have 3 records with correct PhotoalbumId and correct url with GUID jpg. pointing to the folder where 3 .jpg files were present. I opened NewAlbum.aspx and added test album and use picture from your resources, and when ManagePhotoAlbums page was loaded I had only one item, the one I've entered now during this session with no sign for other previous 3. Thanks, Alex
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Ch.14 first try it out |
lrk89 |
BOOK: Beginning ASP.NET 4 : in C# and VB |
7 |
February 10th, 2014 05:12 PM |
| ch: 14, Try it out pg: 515 |
binaryspirit |
BOOK: Beginning ASP.NET 4 : in C# and VB |
6 |
May 4th, 2012 12:49 PM |
| Ch.14 - First try it out |
jxFive |
BOOK: Beginning ASP.NET 4 : in C# and VB |
3 |
November 3rd, 2011 03:55 PM |
| Chp 14, PhotoAlbum extension |
nanonerd |
BOOK: Beginning ASP.NET 4 : in C# and VB |
1 |
October 29th, 2011 11:46 AM |
| Ch 14 Help |
digink |
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 |
3 |
November 3rd, 2009 03:35 PM |
|
 |
|