Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Building Controls / September 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
paul.hester@gmail.com - 20 Sep 2006 05:15 GMT
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
John Saunders - 21 Sep 2006 17:06 GMT
> Hi all,
>
[quoted text clipped - 6 lines]
> 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
paul.hester@gmail.com - 21 Sep 2006 20:54 GMT
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

> > Hi all,
> >
[quoted text clipped - 13 lines]
>
> John
John Saunders - 21 Sep 2006 21:30 GMT
> Hi John,
>
[quoted text clipped - 4 lines]
> 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
paul.hester@gmail.com - 22 Sep 2006 22:07 GMT
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

> > Hi John,
> >
[quoted text clipped - 12 lines]
>
> John
John Saunders - 22 Sep 2006 22:29 GMT
> 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
Gaurav Vaish (www.EduJiniOnline.com) - 24 Sep 2006 07:10 GMT
> 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>".

For your Control, have ToolboxData attribute with appropriate values.

eg:

[ToolboxData("{0}:ControlName runat='server />"]
public class MyCustomControl : Control
{
   ...
}

Signature

Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.com
http://www.edujinionline.com
http://articles.edujinionline.com/webservices
-------------------


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.