Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
|
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
 
Old February 15th, 2014, 04:21 AM
Registered User
 
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..
 
Old February 15th, 2014, 10:24 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!
The Following User Says Thank You to Imar For This Useful Post:
Tobi (February 19th, 2014)
 
Old February 19th, 2014, 08:03 AM
Registered User
 
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.





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





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