Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : 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 December 29th, 2013, 06:24 AM
Registered User
 
Join Date: Dec 2013
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
Default Chapter 15 - Managing Exceptions

Hi,

I'm currently doing the try it out on p. 575 - "Handling Errors when Deleting Rows".

The exercise involves writing a handler method that fires when a user tries to delete a row from the Genres table that has reviews associated with it. A Label is added above the GridView that prints an error message if the user tries to do this (in Genres.aspx)-

Code:
  <asp:Label ID="ErrorMessage" runat="server" CssClass="ErrorMessage" EnableViewState="False"></asp:Label>
In the code behind file the handler method catches the exception and sets the text property of the label-

Code:
protected void SqlDataSource1_Deleted(object sender, SqlDataSourceStatusEventArgs e)
  {
    if (e.Exception != null && e.Exception is SqlException)
    {
      SqlException myException = (SqlException)e.Exception;
      if (myException.Number == 547)
      {
        ErrorMessage.Text = @"Sorry, you can't delete this genre because it has associated reviews that you need to delete first.";
        e.ExceptionHandled = true;
      }
    }
  }
}
However, when I attempt to build the site to view the page I get the following error-
Code:
C:\BegASPNET\Site\Management\Genres.aspx.cs(42,9): error CS0103: The name 'ErrorMessage' does not exist in the current context
I've even tried removing my own files and substituting them with the ones from the Chapter 15 source code download, but still get the same error.

Any ideas on what might be happening?

All help greatly appreciated,

Justin

Last edited by waysgoose; December 29th, 2013 at 07:15 PM.. Reason: Correct Spelling
 
Old January 2nd, 2014, 09:37 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,

Could you have a copy of the page in the same folder? It could be that your markup and Code Behind are not in sync. Check the site's folder on disk to see if there are any files you don't see in the Solution Explorer. Otherise, can you post the full code for the page and the Code Behind?

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!
The Following User Says Thank You to Imar For This Useful Post:
waysgoose (January 4th, 2014)
 
Old January 4th, 2014, 05:43 AM
Registered User
 
Join Date: Dec 2013
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Hi Imar,

In the end I just deleted the whole Management folder and started again.

Lo and behold the error disappeared and my code works perfectly.

Just one for the "I don't know what happened" basket I guess.

Must have been an error in my code somewhere. I guess once I reach the chapter on debugging I'll have the tools to fix that kind of thing.

Cheers,

Justin





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 15 Try Femi Sonuga BOOK: Knight's Microsoft Business Intelligence 24-Hour Trainer 1 February 22nd, 2012 11:29 PM
Chapter 7 -- no "Enable Obj-C exceptions" option lawnboy34 BOOK: Beginning Mac OS X Programming 1 April 4th, 2007 05:19 AM
chapter 15 manal_sag BOOK: Beginning ASP 3.0 2 March 13th, 2006 04:48 PM
Chapter 15 rrlevron BOOK: Beginning ASP 3.0 0 November 17th, 2005 03:38 PM
Chapter 15 help Lorenzo_G BOOK: Beginning ASP 3.0 1 November 27th, 2003 01:00 PM





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