how to render <br> tag from a user control?

Discussion in 'ASP .Net' started by Steve Richter, Jun 29, 2007.

  1. I am using HtmlGenericControl to render html tags like <div> and
    <span>.

    the problem is the <br> tag does not render correctly when I use this
    method. ( it renders as <br></br>, which is seen by the browser as 2
    consecutive <br> tags.

    public class Html_br : HtmlGenericControl
    {
    public Html_br()
    : base("br")
    {
    }
    }

    How can I render the <br> tag so that I can use Controls.Add to add a
    <br> tag to the output of my user control?

    thanks,

    -Steve
     
    Steve Richter, Jun 29, 2007
    #1
    1. Advertising

  2. Steve Richter

    Mark Rae Guest

    "Steve Richter" <> wrote in message
    news:...

    > the problem is the <br> tag does not render correctly when I use this
    > method. ( it renders as <br></br>, which is seen by the browser as 2
    > consecutive <br> tags.


    Yes, it would do... The <br> tag is deprecated these days, and XHTML
    compliance needs it to be self-closing.

    > How can I render the <br> tag so that I can use Controls.Add to add a
    > <br> tag to the output of my user control?


    <br />


    --
    http://www.markrae.net
     
    Mark Rae, Jun 29, 2007
    #2
    1. Advertising

  3. On Jun 29, 3:47 pm, Steve Richter <> wrote:
    > I am using HtmlGenericControl to render html tags like <div> and
    > <span>.
    >
    > the problem is the <br> tag does not render correctly when I use this
    > method. ( it renders as <br></br>, which is seen by the browser as 2
    > consecutive <br> tags.
    >
    > public class Html_br : HtmlGenericControl
    > {
    > public Html_br()
    > : base("br")
    > {
    > }
    > }
    >
    > How can I render the <br> tag so that I can use Controls.Add to add a
    > <br> tag to the output of my user control?
    >
    > thanks,
    >
    > -Steve


    answered my own question. I use the HtmlGenericControl, but I dont
    pass a tag to the constructor and set the InnerHtml to "<br>".

    public class Html_br : HtmlGenericControl
    {
    public Html_br()
    : base("br")
    {
    base.InnerHtml = "<br>";
    }
    }

    still does not seem right, since the documentation of the
    HtmlContainerControl, which is the base class of HtmlGenericControl,
    says:

    "...Serves as the abstract base class for HTML server controls that
    map to HTML elements that are required to have an opening and a
    closing tag. ..."

    <br> does not support the closing tag.

    -Steve
     
    Steve Richter, Jun 29, 2007
    #3
  4. On Jun 29, 4:02 pm, "Mark Rae" <> wrote:
    > "Steve Richter" <> wrote in message
    >
    > news:...
    >
    > > the problem is the <br> tag does not render correctly when I use this
    > > method. ( it renders as <br></br>, which is seen by the browser as 2
    > > consecutive <br> tags.

    >
    > Yes, it would do... The <br> tag is deprecated these days, and XHTML
    > compliance needs it to be self-closing.


    deprecated? jeez. what was it too easy and unambiguous? ;)

    how do I start text on a new line?
    <span style="display:block;">line 1</span>
    <span style="display:block;">line 2</span>

    or has <span> been deprecated also?

    thanks,

    -Steve
     
    Steve Richter, Jun 29, 2007
    #4
  5. Steve Richter

    Mark Rae Guest

    Mark Rae, Jun 29, 2007
    #5
  6. Steve Richter

    Mark Rae Guest

    "Steve Richter" <> wrote in message
    news:...

    >> Yes, it would do... The <br> tag is deprecated these days, and XHTML
    >> compliance needs it to be self-closing.

    >
    > deprecated? jeez. what was it too easy and unambiguous? ;)


    No - it was non-standards compliant...

    > how do I start text on a new line?
    > <span style="display:block;">line 1</span>
    > <span style="display:block;">line 2</span>
    >
    > or has <span> been deprecated also?


    Have you tried <div>...</div>


    --
    http://www.markrae.net
     
    Mark Rae, Jun 29, 2007
    #6
  7. Hi Steve,

    There are few resolutions to the problem:

    1. Depending on the browser caps you will get <br> or <br/>
    public class HtmlBr : System.Web.UI.HtmlControls.HtmlControl
    {
    protected override void Render(HtmlTextWriter writer)
    {
    writer.WriteBreak();
    }
    }

    2. Insetad of deriving simply use LiteralControl

    rendring for HTML 4.0
    myContainer.Controls.Add(new LiteralControl("<br>"));
    or for XHTML 1.0/1.1
    myContainer.Controls.Add(new LiteralControl("<br/>"));


    Please note you and Mark are both right because you're talking abount HTML
    4.01 standard (<br>) and Mark is talking about XHTML <br/> (all tags must be
    valid from XML point of view)

    Regards

    Milosz

    --
    Milosz


    "Steve Richter" wrote:

    > I am using HtmlGenericControl to render html tags like <div> and
    > <span>.
    >
    > the problem is the <br> tag does not render correctly when I use this
    > method. ( it renders as <br></br>, which is seen by the browser as 2
    > consecutive <br> tags.
    >
    > public class Html_br : HtmlGenericControl
    > {
    > public Html_br()
    > : base("br")
    > {
    > }
    > }
    >
    > How can I render the <br> tag so that I can use Controls.Add to add a
    > <br> tag to the output of my user control?
    >
    > thanks,
    >
    > -Steve
    >
    >
     
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=, Jun 30, 2007
    #7
  8. Steve Richter

    Mark Rae Guest

    "Milosz Skalecki [MCAD]" <> wrote in message
    news:...

    > and Mark is talking about XHTML <br/>


    Actually, it's <br />

    The space is important for some browsers...


    --
    http://www.markrae.net
     
    Mark Rae, Jun 30, 2007
    #8
    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. Lau Lei Cheong

    Page.Render do not render complete page

    Lau Lei Cheong, May 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,079
    Lau Lei Cheong
    May 15, 2004
  2. =?Utf-8?B?RXJpYw==?=
    Replies:
    3
    Views:
    442
    =?Utf-8?B?RXJpYw==?=
    Oct 7, 2004
  3. shruds
    Replies:
    1
    Views:
    853
    John C. Bollinger
    Jan 27, 2006
  4. Replies:
    0
    Views:
    310
  5. Glenn Gillen
    Replies:
    0
    Views:
    284
    Glenn Gillen
    Nov 17, 2006
Loading...

Share This Page