Custom controls + nested tags

V

VR

Hi, I'm developing a Web Custom Control and I'm facing some problems with
HTML tags that do not have a closing pair (like <br>,<img>).

Let's say I have a loop that create <div> tags and inside it I put some text
and images:

output.renderBeingTag("div")
output.write("some text")
output.renderBeingTag("br")
output.addAttribute("src","myImage.jpg")
output.renderBeingTag("img")

output.renderEndTag() 'img?
output.renderEndTag() 'br?
output.renderEndTag() 'div?

if I use this code, in IE all goes fine, but when I look in the HTML source
code generated by the control I found that I have <img src="myImage.jpg" />
and <br />. Isn't this bad HTML? Will it work on all browsers as MS says?
(It's not surprise that IE interprets it the right way - almost all bad HTML
IE fix it before rendering the screen).

If I remove the renderEndTag() for <br> and <img> all <div> tags start
getting nested one inside another (that's not what I want)

Well, for all tags that do not really have a closing pair I started using
code like output.write("<br>") and, of course, I'm loosing some ASP.Net
functionality, but, can anyone say if it is really the best approach?


Thanks a lot,
Victor Reboucas
 
S

spmm_pls

Hi Victor,

There's nothing wrong with <img src="myImage.jpg" />
and <br />. (Apart from the fact that the img-tag should have an
alt="..." part to validate). It should also work on all up-to-date
browsers.

Good luck!

M.
 
V

VR

Ok, all up-to-date browsers but not to rely on this (including all field
validation that I'm performing in the server instead of in the client) I
wish to know if it should work on all browsers (for ex: IE1.0) not in
up-to-date ones.

Thanks,
Victor
 
A

Andrew_Revinsky

Victor,

this way of representing empty tags, as br and img are, is THE most correct
way of doing so in the context of "everything goes to XML". Actually, it is a
good so called XHTML dialect of HTML, i.e. XML-compliant HTML. Old browsers
don't mind getting <br /> in. And it doesn't have to do anything with IE
"another whim". However, some browsers, as it is stated, old ones, of course,
have troubles eating empty tags in true compact XML's way of representing
them, e.g, <HR/>, i.e without a space inside. So, in order to produce a
two-way compliant (X)HTML, automatic HTMLformatters insert a space. It is
advisabe for your work, as well. Mark an XHTML specification for further
personal reading.

Best regards,

Andrew
 
V

VR

Thanks Andrew,

I know about the XHTML, but what I really need is some kind of SGHTML (SGML
+ HTML), I need to get an HTML for browsers that were released when there
were no XML in the market, just SGML and HTML (I'm targeting an audience in
far-away Brasil, so, I'll not be surprised to found an NS/IE 1.0 accessing
my site)

Thanks for the help.
Victor Reboucas
 
A

Andrew_Revinsky

Victor,

I guess there is a way of doing your output depending on your goals by doing
some switch in HTMLWriter in .NET. Like, "writer.HTMLOption =
HTMLOutput.HTML;" or something like this. If you come across the way how it
is done, please write here for my future reference.

Thanks!
 
S

St. Weasel

Seems like a butt ugly but workable solution is using the
System.Web.UI.WebControls.Literal class/control. The .Net
documentation is not really helpful in understanding this class, but
it's pretty useful (so useful, in fact, that ASP.NET uses it all the
time when it's compiling aspx pages into classes -- easiest way to see
this is check out the autogenerated source when there's a compile
error on an aspx page).

Hope this helps

St. Weasel
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top