p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   BOOK: Professional Web Parts and Custom Controls ASP.NET ISBN: 0-7645-7860-X (http://p2p.wrox.com/book-professional-web-parts-custom-controls-asp-net-isbn-0-7645-7860-x-225/)
-   -   Problem with BookInfo object in Chapter 9 (http://p2p.wrox.com/book-professional-web-parts-custom-controls-asp-net-isbn-0-7645-7860-x/84692-problem-bookinfo-object-chapter-9-a.html)

flashmanTom August 11th, 2011 01:25 PM

Problem with BookInfo object in Chapter 9
 
Hey,

I'm working the example in Chapter 9, but when I try to add the subobjects, the author property is not in the intellisense list. Also I get an error when I try to use the description property, something about it being a type but is being used as property.

Here is my code:

<code>
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace BookInfoCS
{
[
ParseChildren(false)]
[
ToolboxData("<{0}:BookInfo runat=server></{0}:BookInfo>")]
publicclassBookInfo : WebControl
{
privatestring _MainTitle;
privatestring _SubTitle;
privateArrayList _Authors = newArrayList();
privateArrayList _ChildControls;
[
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[
NotifyParentProperty(true)]
[
PersistenceMode(PersistenceMode.InnerProperty)]
publicstring MainTitle
{
get { return _MainTitle; }
set { _MainTitle = value; }
}
[
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[
NotifyParentProperty(true)]
[
PersistenceMode(PersistenceMode.InnerProperty)]
publicstring SubTitle
{
get { return _SubTitle; }
set { _SubTitle = value; }
}
//[PersistenceMode(PersistenceMode.InnerProperty)]
publicArrayList Authors
{
get { return _Authors; }
set { _Authors = value; }
}
privatestring _Description;
publicstring Description
{
get { return _Description; }
set { _Description = value; }
}
publicArrayList ChildControls
{
get { return _ChildControls; }
set { _ChildControls = value; }
}
protectedoverridevoid AddParsedSubObject(object obj)
{
if (obj isAuthor)
{
if (_Authors == null)
{
_Authors =
newArrayList(2);
}
this.Authors.Add(obj);
}
if (obj isTitles)
{
this.MainTitle = ((Titles)obj).Main;
this.SubTitle = ((Titles)obj).SubTitle;
}
if (obj isLiteralControl)
{
Description ds;
ds = (
Description)obj;
this.Description = ds.Text;
}
if (obj isLabel)
this.Controls.Add((WebControl)obj);
}
protectedoverridevoid Render(HtmlTextWriter writer)
{
//base.Render(writer);
writer.Write("<Table>");
foreach (Author aut inthis.Authors)
{
writer.Write(
"<tr>");
writer.Write(
"<tc>" + aut.FirstName + "</tc");
writer.Write(
"<tc>" + aut.LastName + "</tc>");
writer.Write(
"</tr>");
}
writer.Write(
"</Table>");
}
}
publicclassAuthor
{
privatestring _FirstName;
privatestring _LastName;
publicstring FirstName
{
get { return _FirstName; }
set { _FirstName = value; }
}
publicstring LastName
{
get { return _LastName; }
set { _LastName = value; }
}
public Author()
{
//
// TODO: Add constructor logic here
//
}
}
publicclassTitles
{
privatestring _MainTitle;
privatestring _SubTitle;
publicstring Main
{
get { return _MainTitle; }
set { _MainTitle = value; }
}
publicstring SubTitle
{
get { return _SubTitle; }
set { _SubTitle = value; }
}
}
publicclassDescription : LiteralControl
{
}

Any help ...!

Tom
}
</code>


All times are GMT -4. The time now is 02:08 AM.

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