Wrox Programmer Forums
|
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 April 10th, 2011, 01:13 AM
Registered User
 
Join Date: Mar 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Try it out on page 505

I am trying to do the try it out on page 505. I have checked over all of my code. compared the code to your source and I am continually getting the same error when I try to insert from the NEWPHOTOALBUM. The code that ASP.NET is complaining about is this:

Imports PlanetWroxModel

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}",
myPhotoAlbum.Id.ToString()))
End Sub
End Class

ASP.NET keeps on pointing to the Response.redirect code. This is the error that I am getting.

NullReferenceException was unhandled by user code
Object reference not set to an instance of an object.

Troubleshooting tips:
use the "new" keyword to create an object instance.
Check to determine if the object is null before calling the method.
Get general help for this exception.

Any suggestions. I did not see any reference to this in the Erratta.

Fred Fenk
 
Old April 10th, 2011, 04:34 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,

Looks like the object isn't saved correctly (and is thus null). Maybe this helps?

Cannot redirect to ManagePhotoAlbum

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!
 
Old April 13th, 2011, 08:31 AM
Registered User
 
Join Date: Mar 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default New problem

I blew away the last project and started over. I rebuilt the database and have gotten past my original problem. Now I am getting a different problem. Once I enter the new photoalbum on the NewPhotoAlbum asp page I am being taken to the next page ManagePhotoAlbum. But after I enter the information into the text boxes of the next page I get the following error in the database:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Picture_PhotoAlbum". I looked at the databases. In the PhotoAlbum database the information is inserting correctly. In the Picture database nothing is being input into the database. I have followed your instructions. Not sure what to do.


Sincerely,

Fred Fenk
 
Old April 13th, 2011, 11:45 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 Fred,

How are the tables related in the database? Take a look at the relation on the diagram in SQL Server.

Also, can you post the code for the new Album and tthe Picture pages?

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!
 
Old April 13th, 2011, 01:01 PM
Registered User
 
Join Date: Mar 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Try it out on page 505

Ok, I got past that problem. Again I had to restart Chapter 14. I figured it had to do with the database and recreated it. So now everything works except for one thing. When I do the Try it out on page 515 and I try not to enter a .jpg url, I get an error in the ManagePhotoAlbum.aspx.vb code

Protected Sub ListView1_ItemInserting(sender As Object, e As System.Web.UI.WebControls.ListViewInsertEventArgs) Handles ListView1.ItemInserting
Dim FileUpload1 As FileUpload = CType(ListView1.InsertItem.FindControl("FileUpload 1"), FileUpload)
If Not FileUpload1.HasFile OrElse
Not FileUpload1.FileName.ToLower().EndsWith(".jpg") Then
Dim cusValImage As CustomValidator = CType(ListView1.InsertItem.FindControl("cusValImag e"), CustomValidator)
cusValImage.IsValid = False
e.Cancel = True
End If

End Sub

Mainly it does not like the "cusValImage.IsValid = False" is the complaint. The error that I am getting is:
NullReverenceException was unhandled by user code
Object reference not set to an instance of an object

Troubleshooting tips:
Use the "new" keyword to create an object instance.
Check to determine if the object is null before calling the method.
etc

Fred Fenk
 
Old April 13th, 2011, 01:16 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Fred,

Can you show me the markup of that page? In particular, the section that defines the FileUpload and the CustomValidator controls?

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!
 
Old April 13th, 2011, 02:16 PM
Registered User
 
Join Date: Mar 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Try it out on page 505

Here is all of the markup for the ManagePhotoAlbum.aspx that is in the maincontainer section.

<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">
<InsertItemTemplate>
<li style="">
Description:
<asp:RequiredFieldValidator ID="reqDesc" runat="server" ControlToValidate="DescriptionTextBox" ErrorMessage="Enter a description." />
<asp:TextBox ID="DescriptionTextBox" runat="server"
Text='<%# Bind("Description") %>' />
<br />
ToolTip:
<asp:RequiredFieldValidator ID="reqToolTip" runat="server" ControlToValidate="ToolTipTextBox" ErrorMessage="Enter a tool tip." />
<asp:TextBox ID="ToolTipTextBox" runat="server" Text='<%# Bind("ToolTip") %>' />
<br />
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:CustomValidator ID="custValImage" runat="server" ErrorMessage="Select a valid .jpg file."/>
<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">
<WhereParameters>
<asp:QueryStringParameter Name="PhotoAlbumId" QueryStringField="PhotoAlbumId"
Type="Int32" />
</WhereParameters>
</asp:EntityDataSource>
</asp:Content>

This also has the next try it out code incorporated.
 
Old April 13th, 2011, 03:16 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Here you have it:

Code:
 
<asp:CustomValidator ID="custValImage" runat="server" ErrorMessage="Select a valid .jpg file."/>
The control is called custValImage , yet in your code behind you try to find it (using FindControl) as "cusValImage".

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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Page 210:Page object calling a private method from BasePage? aperture8 BOOK: Beginning ASP.NET 4 : in C# and VB 6 August 9th, 2010 07:04 AM
can’t open the page because the server where this page is located isn’t responding m_alsobaai Forum and Wrox.com Feedback 3 July 15th, 2010 06:13 AM
Page 241 Chapter7 No Page button is showing on browser. tota1ecl1pse BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 1 September 18th, 2009 01:03 PM
How to print a web page without title, URL, page #, date and time Mattt C# 2 July 17th, 2009 03:02 AM





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