How to write a control that doesn't require a closing tag

Discussion in 'ASP .Net Building Controls' started by paul.hester, Sep 20, 2006.

  1. paul.hester

    paul.hester Guest

    Hi all,

    I've built a custom control that won't contain any inner content. If I
    derive the control from Control, then the VS editor will always add the
    closing tag when I use the control. I can derive from UserControl and
    it doesn't do this, but I'm not sure whether is the best way to do
    this.

    What is the correct way to make a control that is self-closing (i.e.
    doesn't have a closing tag)?

    Thanks,

    Paul
     
    paul.hester, Sep 20, 2006
    #1
    1. Advertisements

  2. May I ask why you want to do this? You will need the closing tag for XHTML
    compliance, or at least the closing slash:

    <my:tag/>

    John
     
    John Saunders, Sep 21, 2006
    #2
    1. Advertisements

  3. paul.hester

    paul.hester Guest

    Hi John,

    I want the closing slash, just not the closing tags. When the designer
    auto-closes tags, it sometimes appends a " />" and for others it'll
    append a "</my:tag>".

    I just wanted to know the correct way to write a control where the form
    designer knows won't accept any inner content.

    Thanks,

    Paul
     
    paul.hester, Sep 21, 2006
    #3
  4. I don't beleive this is possible with .NET 1.1. Maybe in 2.0, but I don't
    know.

    Will your control produce an error if there is inner content? Would inner
    whitespace be ok?

    John
     
    John Saunders, Sep 21, 2006
    #4
  5. paul.hester

    paul.hester Guest

    The control won't throw an error - it just won't display any of the
    inner content. I just wanted to emulate some of the existing server
    control behaviour where it auto-closes with the "/>". I can achieve
    this by deriving the control from UserControl, but I just thought
    there'd be a better way of doing this.

    Paul
     
    paul.hester, Sep 22, 2006
    #5
  6. Out of curiosity, which controls auto-close like this, other than user
    controls?

    John
     
    John Saunders, Sep 22, 2006
    #6
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.