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 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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 February 15th, 2014, 04:21 AM
Registered User
Points: 22, Level: 1
Points: 22, Level: 1 Points: 22, Level: 1 Points: 22, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2013
Posts: 5
Thanks: 3
Thanked 0 Times in 0 Posts
Post PLEASE HELP WITH THE ERROR IN Chapter 14 LINQ and the ADO.NET Entity Framework

Hello Imaar,

Please can you help me with correcting this error on Chapter 14 - 'Object reference not set to an instance of an object'.

I tried to run the NewPhotoAlbum.aspx page and click 'Insert', but was greeted with that error message. I have tried everything to rectify the error but it still doesn't give.

Please help me out as I am really enjoying this your book and insightful gaining knowledge. I don't want to get deterred.

Below are the codes for both pages (NewPhotoAlbum and ManagePhotoAlbum):

ManagePhotoAlbum

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 a description." />
        <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>' TextMode="MultiLine" />
        <br />
        ToolTip:
        <asp:RequiredFieldValidator ID="reqTooltip" ControlToValidate="ToolTipTextBox" runat="server" ErrorMessage="Enter a tool tip." />
        <asp:TextBox ID="ToolTipTextBox" runat="server" Text='<%# Bind("ToolTip") %>' />
        <br />
        <asp:FileUpload ID="FileUpload1" runat="server" /><br />
        <asp:CustomValidator ID="cusValImage" ErrorMessage="Select a valid .jpg file." runat="server" />
        <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>
    <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="False" />
      </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.PhotoAlbum.Id = @photoAlbumId" OnInserting="EntityDataSource1_Inserting">
    <WhereParameters>
      <asp:QueryStringParameter Name="PhotoAlbumId" QueryStringField="PhotoAlbumId" Type="Int32" />
    </WhereParameters>
  </asp:EntityDataSource>
</asp:Content>
NewPhotoAlbum (CS file)

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PlanetWroxModel;



public partial class _NewPhotoAlbum : BasePage
{
  protected void Page_Load(object sender, EventArgs e)
  {

  }

  protected void EntityDataSource1_Inserted(object sender, EntityDataSourceChangedEventArgs e)
  {
    PhotoAlbum myPhotoAlbum = (PhotoAlbum) e.Entity;
    Response.Redirect(string.Format("ManagePhotoAlbum.aspx?PhotoAlbumId={0} ", myPhotoAlbum.Id.ToString()));
    
  }
}
Thank you.

Tobi

Last edited by Tobi; February 15th, 2014 at 04:26 AM..
Reply With Quote
  #2 (permalink)  
Old February 15th, 2014, 10:24 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

The only difference I see is the space in this string PhotoAlbumId={0} " which shouldn't be there. If that doesn't help, can you post the remaining code (markup and code behind of these two pages)?

Also, do you get the error or ManagePhotoAlbum or on NewPhotoAlbum?

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
The Following User Says Thank You to Imar For This Useful Post:
Tobi (February 19th, 2014)
  #3 (permalink)  
Old February 19th, 2014, 08:03 AM
Registered User
Points: 22, Level: 1
Points: 22, Level: 1 Points: 22, Level: 1 Points: 22, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2013
Posts: 5
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Hello Imar,

Thank you for your feedback. It's now working. really do appreciate.
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
Chapter 14 - Using Data Controls with the Entity Framework nudirection BOOK: Beginning ASP.NET 4.5 : in C# and VB 3 July 11th, 2013 02:29 AM
Chapter 14 LINQ ADO.NET EF ecdhyne BOOK: Beginning ASP.NET 4.5 : in C# and VB 1 June 21st, 2013 03:45 PM
Chapter 14 - ADO.NET Entity Data Model Sean1980 BOOK: Beginning ASP.NET 4 : in C# and VB 3 July 15th, 2011 12:24 PM
Chapter 14 Linq and ado.net entity framework pandukal21 BOOK: Beginning ASP.NET 4 : in C# and VB 8 January 28th, 2011 05:19 AM
confusing in ADO.NET Entity Data Model,Linq to sql angelboy ADO.NET 5 November 21st, 2008 05:01 PM



All times are GMT -4. The time now is 05:42 AM.


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