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

P

paul.hester

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
 
J

John Saunders

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)?

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
 
P

paul.hester

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
 
J

John Saunders

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.

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
 
P

paul.hester

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
 
J

John Saunders

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.

Out of curiosity, which controls auto-close like this, other than user
controls?

John
 

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,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top