Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5.1 > BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 9th, 2015, 06:21 PM
Registered User
Points: 21, Level: 1
Points: 21, Level: 1 Points: 21, Level: 1 Points: 21, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2014
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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!
Reply With Quote
  #2 (permalink)  
Old January 11th, 2015, 03:34 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
__________________
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!
Reply With Quote
  #3 (permalink)  
Old May 29th, 2015, 05:10 AM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2015
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
Reply With Quote
  #4 (permalink)  
Old May 30th, 2015, 11:21 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
__________________
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!
Reply With Quote
  #5 (permalink)  
Old June 1st, 2015, 04:35 AM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2015
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #6 (permalink)  
Old June 8th, 2015, 11:00 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
__________________
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!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Letting user manage content Gudni BOOK: Beginning ASP.NET Web Pages with WebMatrix 4 January 26th, 2013 11:25 AM
Chapter 14 - Inserted photo albums not displaying jrwhite BOOK: Beginning ASP.NET 4 : in C# and VB 0 September 3rd, 2012 02:30 PM
Only admin be able to create albums for users sophia BOOK: Beginning ASP.NET 4 : in C# and VB 9 August 13th, 2012 01:52 AM
All Photo Albums page cbspira BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 7 January 10th, 2009 08:09 AM



All times are GMT -4. The time now is 07:25 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.