Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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 July 20th, 2008, 01:14 PM
Registered User
 
Join Date: May 2008
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Default Chapter 6 pps 226-228 User Selected Theme

I completed the Try It Out in Chapter 6, pps 226-228, Applying the User-Selected Theme.

I'm using C# and code behind.

When I tried Step 3 in the Try it Out on pagd 227 I get this error:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1518: Expected class, delegate, enum, interface, or struct

Source Error:

Line 16: }
Line 17: }
Line 18: private void Page_PreInit(object sender, EventArgs e)
Line 19: {
Line 20: HttpCookie preferredTheme = Request.Cookies.Get("PreferredTheme");

Source File: c:\BegASPNET\Site\App_Code\BasePage.cs Line: 18


I am totally new to ASP.NET 3.5 (or any other version of it). I can see from the error message that the problem is from the BasePage.cs file. (I'm following Imar's book to the bitter end.) So here is what the code in my BasePage looks like.

using System;
using System.Web;
public class BasePage : System.Web.UI.Page
{
  private void Page_PreRender(object sender, EventArgs e)
  {
    if (this.Title == "Untitled Page")
    {
      throw new Exception("Page title cannot be \"Untitled Page\".");
    }
  }
  public BasePage()
  {
    this.PreRender += new EventHandler(Page_PreRender);
    this.PreInit += new EventHandler(Page_PreInit);
  }
}
private void Page_PreInit(object sender, EventArgs e)
{
HttpCookie preferredTheme = Request.Cookies.Get("PreferredTheme");
if (preferredTheme != null)
{
Page.Theme = preferredTheme.Value;
}
}

I've looked all around everywhere I can think of to find an answer and solution to this error without success. I'm hoping to find out here. Bear in mind I need a clear simple understandable answer. Most of this stuff is all Greek to me. Thanks for any help.


Featheriver
 
Old July 20th, 2008, 05:43 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 there,

Take a look at this:

 public BasePage()
 {
   this.PreRender += new EventHandler(Page_PreRender);
   this.PreInit += new EventHandler(Page_PreInit);
 }
}
private void Page_PreInit(object sender, EventArgs e)
{

Notice the last } before private void Page_PreInit?

It shouldn't be there; right now it closes the BasePage class so the code that follows it is no longer in a class and this the compiler "Expect[s a] class, delegate, enum, interface, or struct".

Simply remove it and you're good to go.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 
Old April 20th, 2011, 06:36 AM
Registered User
 
Join Date: Apr 2011
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Default ch6 try it out pg231

Please help


Code:
BasePage

  

Public Class BasePage
    Inherits System.Web.UI.MasterPage

    Dim Title As String

    Private Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles Me.PreInit
        Dim preferredTheme As System.Web.HttpCookie = Request.Cookies.Get("PreferredTheme")
        If preferredTheme IsNot Nothing Then
            Page.Theme = preferredTheme.Value

        End If

    End Sub
    Private Sub Page_Prerender(
       ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender

        If Me.Title = "Untitled Page" Or String.IsNullOrEmpty(Me.Title) Then
            Throw New Exception(
                "Page title cannot be ""Untitled Page"" or an empty string.")
        End If



    End Sub
End Class

thanks

mike
 
Old April 20th, 2011, 07: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 Mike,

Quote:
Please help
With what exactly?

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
Chapter 18: Unable to see the site THEME locochinoloco BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 September 18th, 2008 02:35 AM
(Chapter 6) applying user-selected theme in IE7 phoenixx ASP.NET 3.5 Basics 6 August 26th, 2008 09:49 AM
Chapter 6 User-Selected Theme Question jabo2099 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 August 21st, 2008 03:45 AM
Chapter 7 Navigation Try IT Out pps. 246-247 workib BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 May 22nd, 2008 08:39 PM
VB.net 2005 User theme datagrid alex1985 Visual Studio 2005 7 September 11th, 2007 01:34 PM





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