Wrox Programmer Forums
|
BOOK: Professional Web Parts and Custom Controls ASP.NET ISBN: 0-7645-7860-X
This is the forum to discuss the Wrox book Professional Web Parts and Custom Controls with ASP.NET 2.0 by Peter Vogel; ISBN: 9780764578601
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Web Parts and Custom Controls ASP.NET ISBN: 0-7645-7860-X 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 February 25th, 2006, 01:18 PM
Registered User
 
Join Date: Feb 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Accessing Attributes P137

Good book so far, really can see the potential of this technology.

I've taken the plunge and decided to learn C# and ASP.NET 2.0 whilst working through this book rather than start at the basics, so forgive me if this is a really foolish post, but I'm trying to compile a very basic class based on this section of the book:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MyFirstWebPart
{
    public class BookDetail : System.Web.UI.WebControls.Webparts.WebPart
    {
        [ToolboxData("<{0}:BookDetail runat=server></{0}:BookDetail>")]
        System.ComponentModel.AttributeCollection atts;
        atts = TypeDescriptor.GetAttributes(this);
    }
}

but, when compiling the "atts = TypeDescriptor.." gives me a compilation error:

Error 1 Invalid token '=' in class, struct, or interface member declaration

I can't really find a workaround and online Microsoft help seems to indicate that the above syntax is correct.

I'm using Express versions of Visual Web Developer and Visual C#

Many thanks

 
Old February 25th, 2006, 06:55 PM
Authorized User
 
Join Date: Dec 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ouch--my C# skills aren't everything they should be (and I don't have access to my book right now to see how I'm leading you astray. But shouldn't the attributes line (beginning with "[") precede the class declaration, like this:

[ToolboxData("<{0}:BookDetail runat=server></{0}:BookDetail>")]
public class BookDetail : System.Web.UI.WebControls.Webparts.WebPart

When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.

- Sherlock Holmes, as recorded by Sir A. C. Doyle in "The Blanched Soldier"
 
Old February 26th, 2006, 08:10 PM
Registered User
 
Join Date: Feb 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Peter,

Thanks for your quick reply. Whoops, I think I must have been moving the attribute definition around whilst trying to get this to work, so it wasn't an issue with your book. Alas, with the attribute definition in the correct place it is still giving me these issues. I'll try the VB version tomorrow at work.

J.

 
Old February 27th, 2006, 07:13 AM
Registered User
 
Join Date: Feb 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

As promised I tried this in VB. I got a different compile error "Declaration Expected". I was able to find very quickly online a valid case for this error (as opposed to the spurious C# error message.) I will remember this in future: if I get an error in C# that makes no sense and is difficult to get help online with, I will try it in VB and have a different line-of-attack.

Anyway, it alluded to the fact that this code needs to be wrapped in a method - how did I not spot that! Oh well, I won't fall for that one again.

Now I'm getting an issue with the line :

ts = atts(GetType(ToolboxDataAttribute));

I will investigate further and also download your full code for the book; that will probably highlight a fair few issues with my coding so I won't have to keep burdening people with silly requests on this forum.

Many thanks

J.







Similar Threads
Thread Thread Starter Forum Replies Last Post
Get ACL Attributes ruisolid C# 2005 0 August 23rd, 2007 07:41 AM
How to handle several attributes? sebhoff XSLT 2 March 20th, 2007 02:47 AM
restrictions on attributes kfir XML 2 May 30th, 2006 04:35 AM
Accessing Attributes of Siblings AForgue XSLT 2 November 4th, 2003 01:39 PM





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