Can someone help me with this error from Try It Out Inserting and Deleting Data with the ListView Control?
Error
Server Error in '/Site' Application.
Object reference not set to an instance of an object.
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 6: Protected Sub EntityDataSource1_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.EntityDataSourceChangedE ventArgs) Handles EntityDataSource1.Inserted
Line 7: Dim myPhotoAlbum As PhotoAlbum = CType(e.Entity, PhotoAlbum)
Line 8: Response.Redirect(String.Format("ManagePhotoAlbum. aspx?PhotoAlbumId={0}", New String(myPhotoAlbum.Id.ToString())))
Line 9: End Sub
Line 10: End Class
Source File: N:\NewASP\Site\NewPhotoAlbum.aspx.
vb Line: 8
Here is my code for aspx
<%@ Page Title="Create New Photo Album" Language="
VB" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="false" CodeFile="NewPhotoAlbum.aspx.
vb" 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" 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=TesterEntities" DefaultContainerName="PlanetWroxEntities" EnableFlattening="False"
EnableInsert="True" EntitySetName="PhotoAlbums" OnInserted="EntityDataSource1_Inserted">
</asp:EntityDataSource>
</asp:Content>
Code behind
Imports TesterModel
Partial Class _NewPhotoAlbum
Inherits BasePage
Protected Sub EntityDataSource1_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.EntityDataSourceChangedE ventArgs) Handles EntityDataSource1.Inserted
Dim myPhotoAlbum As PhotoAlbum = CType(e.Entity, PhotoAlbum)
Response.Redirect(String.Format("ManagePhotoAlbum. aspx?PhotoAlbumId={0}", New String(myPhotoAlbum.Id.ToString())))
End Sub
End Class