Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 25th, 2006, 01:18 PM
Registered User
 
Join Date: Feb 2006
Location: , , .
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

  #2 (permalink)  
Old February 25th, 2006, 06:55 PM
Authorized User
 
Join Date: Dec 2005
Location: Goderich, Ontario, Canada.
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"
  #3 (permalink)  
Old February 26th, 2006, 08:10 PM
Registered User
 
Join Date: Feb 2006
Location: , , .
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.

  #4 (permalink)  
Old February 27th, 2006, 07:13 AM
Registered User
 
Join Date: Feb 2006
Location: , , .
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.


 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:39 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.