Derived BulletedList

Discussion in 'ASP .Net Web Controls' started by J055, Mar 7, 2007.

  1. J055

    J055 Guest

    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
     
    J055, Mar 7, 2007
    #1
    1. Advertising

  2. J055

    J055 Guest

    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();
    }
     
    J055, Mar 7, 2007
    #2
    1. Advertising

  3. 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.
     
    Steven Cheng[MSFT], Mar 8, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. benliu
    Replies:
    0
    Views:
    375
    benliu
    Aug 22, 2006
  2. Stan SR

    BulletedList inside BulletedList

    Stan SR, Aug 31, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    2,879
    Stan SR
    Aug 31, 2006
  3. Tony
    Replies:
    0
    Views:
    349
  4. Replies:
    1
    Views:
    397
    myork
    May 23, 2007
  5. Replies:
    1
    Views:
    389
    Victor Bazarov
    May 23, 2007
Loading...

Share This Page