Custom controls + nested tags

Discussion in 'ASP .Net Web Controls' started by VR, Sep 9, 2004.

  1. VR

    VR Guest

    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
     
    VR, Sep 9, 2004
    #1
    1. Advertising

  2. VR

    spmm_pls Guest

    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.
     
    spmm_pls, Sep 10, 2004
    #2
    1. Advertising

  3. VR

    VR Guest

    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


    "spmm_pls" <> wrote in message
    news:...
    > 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.
     
    VR, Sep 11, 2004
    #3
  4. 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

    "VR" wrote:

    > 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
    >
    >
    >
    >
     
    Andrew_Revinsky, Sep 14, 2004
    #4
  5. VR

    VR Guest

    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


    "Andrew_Revinsky" <> wrote in
    message news:...
    > 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
    >
    > "VR" wrote:
    >
    >> 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
    >>
    >>
    >>
    >>
     
    VR, Sep 15, 2004
    #5
  6. 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!

    "VR" wrote:

    > 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
    >
    >
    > "Andrew_Revinsky" <> wrote in
    > message news:...
    > > 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
    > >
    > > "VR" wrote:
    > >
    > >> 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
    > >>
    > >>
    > >>
    > >>

    >
    >
    >
     
    Andrew_Revinsky, Sep 20, 2004
    #6
  7. VR

    St. Weasel Guest

    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
     
    St. Weasel, Sep 20, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dean H. Saxe
    Replies:
    0
    Views:
    1,052
    Dean H. Saxe
    Jan 3, 2004
  2. Ranganath

    Custom Tags within Custom Tags.

    Ranganath, Oct 17, 2003, in forum: Java
    Replies:
    2
    Views:
    470
    Ranganath
    Oct 21, 2003
  3. Mike
    Replies:
    3
    Views:
    889
    Michael Borgwardt
    Jan 9, 2004
  4. A. Brinkmann
    Replies:
    2
    Views:
    1,090
    A. Brinkmann
    Apr 16, 2004
  5. Dave
    Replies:
    0
    Views:
    456
Loading...

Share This Page