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 January 5th, 2011, 04:08 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 code that's causing the error is from the autogenerated code for the Entity Framework model. Tyeh reason you're getting this error is because you'e trying to assign null to the ImageUrl property because you forgoty to take out the TextBox for the ImageUrl:

Code:
 
<asp:TextBox ID="ImageUrlTextBox" runat="server" Text='<%# Bind("ImageUrl") %>' />
With this line in the InsertItemTemplate, ASP.NET tries to assign the value of the TextBox to the ImageUrl control. This fails because a) the Text is null, and b) ImageUrl doesn't allow nulls.

Once you take out this line, ASP.NET doesn't assign an explicit value to the ImageUrl property (under the hood it's still null, but validation is postponed until you save the item to the database). Then the Inserting event fires and you manually assign the ImageUrl a valid value so that when you save, everything works well.

Hope this helps,

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:
ksnortum (January 5th, 2011)
 
Old January 5th, 2011, 05:13 PM
Authorized User
 
Join Date: Dec 2010
Posts: 22
Thanks: 10
Thanked 0 Times in 0 Posts
Default Thanks

It looks like that was it. thanks.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Object reference not set to an instance of an object. dotnet_user C# 2008 aka C# 3.0 2 April 6th, 2011 06:11 AM
Chap 13 pg448: Object reference not set to an instance of an object tomche BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 15 August 8th, 2009 06:14 AM
Object variable not set or With Block not set brucechess BOOK: Beginning VB.NET Databases 1 March 3rd, 2009 07:30 AM
Chapter 14 TIO #1406 Object That Provides a DataSe dcollins BOOK: Beginning ASP.NET 2.0 and Databases 0 October 23rd, 2006 01:35 PM
Object Reference not set to an instance of object srinivas_chakka ASP.NET 1.0 and 1.1 Professional 0 February 8th, 2006 11:56 AM





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