chapter 14 try out page 497
Hi Imar,
When I try to view NewPhotoAlbum.aspx getting following error
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 17:
Line 18: PhotoAlbum myPhotoAlbum = (PhotoAlbum)e.Entity;
Line 19: Response.Redirect(string.Format("ManagePhotoAlbum. aspx?PhotoAlbumId={0}", myPhotoAlbum.Id.ToString()));
Line 20: }
Line 21: }
I verified my code with the downloaded code there is no difference
Also done debugging it says myPhotoAlbum is null
Dont know how to fix it.
My NewPhotoAlbum.aspx is
<%@ Page Title="Create New Photo Album" Language="C#" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="true" CodeFile="NewPhotoAlbum.aspx.cs" Inherits="_NewPhotoAlbum" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" runat="Server">
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="Id" DataSourceID="EntityDataSource1" DefaultMode="Insert" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" InsertVisible="False" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:CommandField ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=PlanetWroxEntities" DefaultContainerName="PlanetWroxEntities" EnableFlattening="False" EnableInsert="True" EntitySetName="PhotoAlbums" OnInserted="EntityDataSource1_Inserted">
</asp:EntityDataSource>
</asp:Content>
My NewPhotoAlbum.aspx.cs is
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()));
}
}
Pl. help me fix the code.
Mary Sunish
Last edited by marysunish; May 10th, 2012 at 09:49 PM..
|