473,324 Members | 2,313 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Using the System.Web.UI.HtmlTextWriter to create self-closing tags

I am using the System.Web.UI.HtmlTextWriter, and would like to create tags
that are self-closing (such as <tagname />). The RenderBeginTag method does
not offer the option of making a self-closing tag (I think it should have an
optional boolean parameter to specify whether it is self-closing, but it
doesn't). I know how to make self-closing tags using the Write methods, but
this requires calling a write method for every attribute and style, and does
not allow you to use the System.Web.UI.HtmlTextWriterAttribute or
System.Web.UI.HtmlTextWriterStyle enumerations. Is there a built-in way that
I am missing to make self-closing tags? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Oct 26 '08 #1
1 5088
On Sun, 26 Oct 2008 23:49:08 +0100, Nathan Sokalski
<nj********@hotmail.comwrote:
Is there a built-in way that I am missing to make self-closing tags?
I just tried the following code in a simple console app:

HtmlTextWriter writer = new HtmlTextWriter(Console.Out);
writer.RenderBeginTag("p");
writer.RenderBeginTag("img");
writer.RenderEndTag();
writer.RenderEndTag();

This yields the following written in my console:
<p><img /></p>

Doing the same with "div" as argument for the second call to
RenderBeginTag() yields a different result, where the div is printed with
an open and empty body. I believe this i by design, as it does not make
any sense to have a self-closing div.

What kind of HTML element are you working with?

--
Joern Schou-Rode
http://malamute.dk/
Oct 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter Petrillo | last post by:
The Access development group here at this company has exported its reports in xml format from Access 2003. I have no influence on how they have created them. I received the following files xm...
4
by: Kevin Phifer | last post by:
Ok, before anyone freaks out, I have a solution I need to create that gathers content from maybe different places. Each one can return a <form> in the html, so its the classic can't have more than...
1
by: Hozi | last post by:
I am getting the below error when asp.net tries to parse the .aspx file. The funny part is that the error only seems to be happening when viewing the page throuh IE 6 and not Netscape browsers. I...
3
by: msnews.microsoft.com | last post by:
Hello All, I am trying to write Web Controls and in most of the samples I came across, I am seeing the following function where a HTML string is written to create HTML Controls. ///...
0
by: IkBenHet | last post by:
This error below happens sometimes when accessing the page. When you refresh the page it is ok. Please help. Server Error in '/' Application....
12
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control...
2
by: fmakopo | last post by:
I am trying to save html page using C# because i want to save the page on the server not on the client side. I can do that using Javascript the problem that i am having i want to save the page on...
2
by: Tugrul HELVACI | last post by:
I'm using Delphi 2006 and I have a class defination like this: TPerson = class fPersonName : String; fPersonSurName : String; fPersonAge : Integer; published property PersonName : String...
1
by: Brett Wesoloski | last post by:
I am new to using template columns. I am just trying to create a data grid with a bound column and another column with a imagebutton in it. What I have always done in the past was to then create...
2
by: phanimadhav | last post by:
Hello Experts, I developed following code for excel file creation by using Dataset.But i got the following error(NullRefernec Exception was caught) at the response.End() My...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.