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

January 9th, 2015, 06:21 PM
|
|
Registered User
|
|
Join Date: Dec 2014
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Chapter 17 TRY IT OUT: Letting Users Manage Their Own Photo Albums
Nearing the end of the book but I'm still encountering situations where the text in the book doesn't match the downloaded code. This is another one of them, and when I run the downloaded code for this TRY IT OUT, the result is not as expected (more on that shortly).
Here are some of the discrepancies I've encountered between the book (Kindle version) and the downloaded code:
Step 4 is radically different.
Step 6 refers to a DropDownList control called "PhotoAlbumList" however no such control exists. In the downloaded code it is correctly referred to as "DropDownList1"
This and MANY other TRY IT OUT examples in the book require adding "using PlanetWroxModel;" to the namespace references but no instruction is given for this. The downloaded code includes these references but the book does not.
Finally, when I run the code and log in as the owner of an album, no link appears that will allow me to edit that album. It does appear if I log on as a member of the Managers role however.
Has anyone else encountered this? Any idea how to fix it?
I haven't included any code because I'm using the unchanged downloaded code, however if you need any other information please let me know.
Thanks!
|
|

January 11th, 2015, 03:34 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Do the versions of the book and Visual Studio match? For the ASP.NET 4.5.1 book, you should be using Visual Studio 2013, and not an earlier version. Is that the case?
Step 4 could be different if you're using a different version of Entity Framework which would be the case if you're using an older version VS.
For Step 6, are you sure you're working with the correct file? The file /PhotoAlbum/Default.aspx that you should open does have a control called PhotoAlbumList.
>> The downloaded code includes these references but the book does not.
Which files did you download? The download for ASP.NET 4.5.1 doesn't have them. Again, this seems to suggest a mismatch between versions.
>> Finally, when I run the code and log in as the owner of an album, no link appears that will allow me to edit that album. It does appear if I log on as a member of the Managers role however.
Does this happen with the downloaded code as well? It works for me, so something must be going on your end....
Imar
|
|

May 29th, 2015, 05:10 AM
|
|
Registered User
|
|
Join Date: May 2015
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Chp17 Try it Out: managing photo albums
Hi there,
I am having a problem in Chapter 17 where the owner of the album can't edit their album. But if logged in as the manager I can. Not sure where I am going wrong :-( New to forums so not sure how much info to post?
Thanks
|
|

May 30th, 2015, 11:21 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
What is broken exactly? Can't you edit the review or don't you see the edit link.
Can you post the code for the ASPX and Code Behind for that page that doesn't behave as expected?
Cheers,
Imar
|
|

June 1st, 2015, 04:35 AM
|
|
Registered User
|
|
Join Date: May 2015
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for getting back to me. In the ~/PhotoAlbums/Defaults.aspx file, I can't see the edit link if I am logged in as a user, even if i own the album. (I can see the link if i am logged in as the manager.)
Instead of using the PanetWroxEntities I am using Smile CycleEntities based on the database I am working off.
The code from Default.aspx is:
Code:
<%@ Page Title="Photos" Language="C#" MasterPageFile="~/MasterPages/FrontEnd.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<asp:UpdatePanel runat="server">
<ContentTemplate>
<header>Photos</header>
<section id ="PageContent">
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataSourceID="EntityDataSource1" DataTextField="Name" DataValueField="Id" Width="200px">
</asp:DropDownList>
<asp:ListView ID="ListView1" runat="server"
DataKeyNames="Id"
DataSourceID="EntityDataSource2"
ItemType="SmileCycleModel.Picture"
OnDataBound="ListView1_DataBound">
<EmptyDataTemplate>
No data was returned.
</EmptyDataTemplate>
<ItemTemplate>
<li>
ImageUrl:
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Item.ImageUrl %>' ToolTip='<%# Item.ToolTip %>'/>
Description:
<asp:Label ID="DescriptionLabel" runat="server" Text='<%# Item.Description %>' />
<br />
</li>
</ItemTemplate>
<LayoutTemplate>
<ul class="ItemContainer">
<li runat="server" id="itemPlaceholder" />
</ul>
<div style="clear:both">
<asp:DataPager ID="DataPager1" runat="server" PageSize ="3">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</div>
</LayoutTemplate>
</asp:ListView>
<br />
<br />
<asp:HyperLink ID="EditLink" Text="Edit Photo Album" runat="server" />
<asp:EntityDataSource ID="EntityDataSource2" runat="server"
AutoGenerateWhereClause="True" ConnectionString="name=SmileCycleEntities"
DefaultContainerName="SmileCycleEntities" EnableFlattening="False"
EntitySetName="Pictures" Where="">
<WhereParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="PhotoAlbumID" PropertyName="SelectedValue" Type="Int32" />
</WhereParameters>
</asp:EntityDataSource>
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=SmileCycleEntities"
DefaultContainerName="SmileCycleEntities" EnableFlattening="False"
EntitySetName="PhotoAlbums" Select="it.[Id], it.[Name]">
</asp:EntityDataSource>
</section>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
The code behind Default.aspx.cs is:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SmileCycleModel;
public partial class _Default : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ListView1_DataBound(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(DropDownList1.SelectedValue))
{
int photoAlbumId = Convert.ToInt32(DropDownList1.SelectedValue);
using (SmileCycleEntities myEntities = new SmileCycleEntities())
{
string photoAlbumOwner = (from p in myEntities.PhotoAlbums
where p.Id == photoAlbumId
select p.UserName).Single();
if (User.Identity.IsAuthenticated && (User.Identity.Name == photoAlbumOwner || User.IsInRole("Managers")))
{
EditLink.NavigateUrl = string.Format(
"~/ManagePhotoAlbum.aspx?PhotoAlbumId={0}", DropDownList1.SelectedValue);
EditLink.Visible = true;
}
else
{
EditLink.Visible = false;
}
}
}
else
{
EditLink.Visible = false;
}
}
}
I have played around with the variables and from what I can see there seems to be a problem with photoAlbumOwner not being the same as User.Identity.Name.
Thanks again
Dave
|
|

June 8th, 2015, 11:00 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi Dave,
A few suggestions:
1. Check the database. Maybe the owner isn't stored correctly? Also, check the code that assigns the owner and see if you can find an issue there.
2. Debug the application and break on the line that that compares the owner and the current user. That may also shed some light.
Cheers,
Imar
|
|
 |
|