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
Mark Rae - 29 Jun 2007 21:02 GMT
> 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 />

Signature
http://www.markrae.net
Steve Richter - 29 Jun 2007 21:19 GMT
> > 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
Mark Rae - 29 Jun 2007 21:38 GMT
>> 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>

Signature
http://www.markrae.net
Steve Richter - 29 Jun 2007 21:09 GMT
> I am using HtmlGenericControl to render html tags like <div> and
> <span>.
[quoted text clipped - 17 lines]
>
> -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
Mark Rae - 29 Jun 2007 21:37 GMT
> "...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.
Yes it does:
http://www.w3schools.com/xhtml/xhtml_howto.asp

Signature
http://www.markrae.net
Milosz Skalecki [MCAD] - 30 Jun 2007 12:00 GMT
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

Signature
Milosz
> I am using HtmlGenericControl to render html tags like <div> and
> <span>.
[quoted text clipped - 17 lines]
>
> -Steve
Mark Rae - 30 Jun 2007 13:47 GMT
> and Mark is talking about XHTML <br/>
Actually, it's <br />
The space is important for some browsers...

Signature
http://www.markrae.net