"Text is not allowed between the opening and closing tag"?

D

Dave

Here's my custom control (taken and modified from ASP.NET Unleashed 2.0)...

<cc1:ImageRotator ID="ImageRotator1" runat="server">
<cc1:ImageItem AlternateText="first item..." />
<cc1:ImageItem AlternateText="second item..." />
<cc1:ImageItem>abc</cc1:ImageItem> <--ERROR appears here.
</cc1:ImageRotator>

However, the control runs and the literal content "abc" gets parsed OK.
What do I have to do so Visual Studio doesn't show this error at compile or
the IDE?. It works but is misleading if other developers want to use this
control in their apps.

The code for the ImageItem class is below...if literal text is placed
between I want to default it to set the AlternatingText property. Just like
the ListItem text defaults to the Text property.
.....

public class ImageItem : IParserAccessor
{
private string _imageUrl;
private string _alternateText;

public string ImageUrl
{
get { return _imageUrl; }
set { _imageUrl = value; }
}

public string AlternateText
{
get { return _alternateText; }
set { _alternateText = value; }
}

//only called when there is literal text placed between open/close
tags
public void AddParsedSubObject(object obj)
{
if (obj is LiteralControl)
this.AlternateText = ((LiteralControl)obj).Text;
else
throw new System.Web.HttpException("Error parsing ImageItem
class");
}
}
 
D

Dave

The solution is to add:

[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
public string AlternateText
{ ...
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top