Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5.1 > BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
|
BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5.1: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-84677-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5.1 : 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 18th, 2016, 09:42 PM
Authorized User
 
Join Date: Nov 2014
Posts: 91
Thanks: 2
Thanked 1 Time in 1 Post
Default Chapter 16: Checking Roles with IsUserInRole at Run Time

Hi Imar,

I got the yellow screen of death for the last Try It Out in Chapter 16. Here's is the output:

Code:
Server Error in '/' 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 79:         case ListViewItemType.DataItem:
Line 80:           Button deleteButton = (Button)e.Item.FindControl("DeleteButtom");
Line 81:           deleteButton.Visible = Roles.IsUserInRole("Managers");
Line 82:           break;
Line 83:       }

Source File: c:\BegASPNET\Site\ManagePhotoAlbum.aspx.cs    Line: 81 

Stack Trace: 

[NullReferenceException: Object reference not set to an instance of an object.]
   _ManagePhotoAlbum.ListView1_ItemCreated(Object sender, ListViewItemEventArgs e) in c:\BegASPNET\Site\ManagePhotoAlbum.aspx.cs:81
   System.Web.UI.WebControls.ListView.OnItemCreated(ListViewItemEventArgs e) +91
   System.Web.UI.WebControls.ListView.CreateItemsWithoutGroups(ListViewPagedDataSource dataSource, Boolean dataBinding, InsertItemPosition insertPosition, ArrayList keyArray) +739
   System.Web.UI.WebControls.ListView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +1032
   System.Web.UI.WebControls.ListView.PerformDataBinding(IEnumerable data) +35
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +128
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +34
   System.Web.UI.WebControls.ModelDataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +80
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
   System.Web.UI.WebControls.ListView.PerformSelect() +102
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +114
   System.Web.UI.WebControls.ListView.CreateChildControls() +52
   System.Web.UI.Control.EnsureChildControls() +92
   System.Web.UI.Control.PreRenderRecursiveInternal() +42
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4775


________________________________________
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1038.0
Please help resolve.
 
Old January 19th, 2016, 03: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

You'll have to debug the code to see what's null exactly and why but my guess is this:

Button deleteButton = (Button)e.Item.FindControl("DeleteButtom");

Your button may have a different name in the UI;l for example DeleteButton with an N instead of DeleteButtom with an M.

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!
 
Old January 19th, 2016, 09:53 AM
Authorized User
 
Join Date: Nov 2014
Posts: 91
Thanks: 2
Thanked 1 Time in 1 Post
Smile Chapter 16: Checking Roles with IsUserInRole at Run Time

Thanks Imar. The typo was the problem. I haven't gotten the hang of using the debugger. But, I will skip Chapter 17 and move on to Chapter 18.

Thank you again.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 16 - Try it Out Checking Roles with IsUserInRole at Runtime skachy BOOK: Beginning ASP.NET 4 : in C# and VB 7 November 17th, 2018 04:23 PM
Chapter 16: Using the WSAT to Manage User Accounts and Roles phztfte1 BOOK: Beginning ASP.NET 4.5.1 : in C# and VB 9 January 18th, 2016 04:29 PM
Chapter 16:Page 615 try it out Checking Roles with IsUserInRole at Runtime lstew452 BOOK: Beginning ASP.NET 4 : in C# and VB 2 July 5th, 2010 02:20 PM
Chapter 27 Run-time Error DaveHowland BOOK: Professional VB 2005 ISBN: 0-7645-7536-8 7 February 16th, 2008 09:32 PM
Roles.deleteuser 16-26 troubles ufdylan BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 0 August 2nd, 2007 01:35 PM





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