Derived BulletedList

J

J055

Hi

I want to make a simple modification to the BulletedList control. I would
like the control to render with a DIV element wrapped around it, e.g.

<div id="MessagesList1" class="messages">
<ul>
<li>Item 1</li>
</ul>
</div>

The control including the div should only render if the BulletedList
contains items.
I've had a go at overriding the render method

protected override void Render(HtmlTextWriter writer)
{
if (!DesignMode)
{
if (this.Items.Count > 0)
{
writer.AddAttribute(HtmlTextWriterAttribute.Class,
"messages");
writer.RenderBeginTag(HtmlTextWriterTag.Div);
base.Render(writer);
writer.RenderEndTag();
}
}
else
{
base.Render(writer);
}
}

This works in the browser but It doesn't seem quite right in DesignMode. I
get the following error:

Error 1 Element 'ListItem' is not a known element. This can occur if there
is a compilation error in the Web site.

Also it would be better i think if the control ID was fixed against the div
tag, not the UL or OL.

What would be my best approach here?

Thanks
Andrew
 
J

J055

Hi

I've got behaving as I need in the browser now. Used the reflector tool to
get the TagKeyInternal method so the control would still work like the
BullettList. However I still get an error in design mode because it doesn't
recognise the LIstItems. BY the way I'm doing this so it copies the way the
ValidationSummary control renders. Then I only need one set of css styles
and they will always match when displayed side by side on a web page.

Thanks
Andrew


protected override HtmlTextWriterTag TagKey
{
get
{
return HtmlTextWriterTag.Div;
}
}

internal HtmlTextWriterTag TagKeyInternal
{
get
{
switch (this.BulletStyle)
{
case BulletStyle.NotSet:
return HtmlTextWriterTag.Ul;

case BulletStyle.Disc:
case BulletStyle.Circle:
case BulletStyle.Square:
return HtmlTextWriterTag.Ul;

case BulletStyle.CustomImage:
return HtmlTextWriterTag.Ul;
}
return HtmlTextWriterTag.Ol;
}
}

protected override void RenderContents(HtmlTextWriter writer)
{
writer.RenderBeginTag(TagKeyInternal);
base.RenderContents(writer);
writer.RenderEndTag();
}
 
S

Steven Cheng[MSFT]

Hi Andrew,

Regarding on the custom BulledList control that need an additional <div>
wrapper tag, I think your current implementation is reasonable. As for the
design-time error, it is actually due to the schema validation. Since your
custom BulletedList control's control tag hasn't been in the built-in aspx
control schema, when you add <asp:ListItem> tags into your custom
<cc1:MyBulletedList> tag, the IDE will report such design-time validation
error. This is an expected behavior for most custom controls which will
include other built-in control's inner tag as its own child tag element.
Anyway, I think you can simply ignore it as the runtime control since it
doesn't affect any of the runtime control lifecycle or processing.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top