XhtmlTextWriter writes table and attributes problem
am 29.01.2008 02:22:01 von HardyWang
Hi all,
I am building a Composite control, and I need to render Xhtml content for my
control. Here is my sample code:
protected override void Render(HtmlTextWriter output) {
XhtmlTextWriter xWriter = new XhtmlTextWriter(output);
xWriter.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
xWriter.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
xWriter.RenderBeginTag(HtmlTextWriterTag.Table);
xWriter.RenderBeginTag(HtmlTextWriterTag.Tr);
xWriter.RenderBeginTag(HtmlTextWriterTag.Td);
xWriter.Write("Hello world");
xWriter.RenderEndTag();
xWriter.RenderEndTag();
xWriter.RenderEndTag();
xWriter.AddAttribute("src", "logo.gif");
xWriter.RenderBeginTag(HtmlTextWriterTag.Img);
xWriter.RenderEndTag();
}
And here is the output
Why attributes are not added to my table tag, but OK for img tag?
Do I miss something?
--
Regards
Hardy
RE: XhtmlTextWriter writes table and attributes problem
am 29.01.2008 03:03:28 von HardyWang
It seems that it is almost impossible to write "0" as attribute value im many
cases.
For example:
xWriter.AddAttribute(HtmlTextWriterAttribute.Src, "a.gif");
xWriter.AddAttribute(HtmlTextWriterAttribute.Border, "0");
xWriter.RenderBeginTag(HtmlTextWriterTag.Img);
xWriter.RenderEndTag();
Won't add border="0" to img tag.
xWriter.AddAttribute(HtmlTextWriterAttribute.Src, "a.gif");
xWriter.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, "0px");
xWriter.RenderBeginTag(HtmlTextWriterTag.Img);
xWriter.RenderEndTag();
Won't add border="0" to img tag.
xWriter.AddAttribute(HtmlTextWriterAttribute.Src, "a.gif");
xWriter.AddAttribute("borderwidth", "0");
xWriter.RenderBeginTag(HtmlTextWriterTag.Img);
xWriter.RenderEndTag();
Won't add border="0" to img tag.
xWriter.AddAttribute(HtmlTextWriterAttribute.Src, "a.gif");
xWriter.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, "0");
xWriter.RenderBeginTag(HtmlTextWriterTag.Img);
xWriter.RenderEndTag();
Won't add border="0" to img tag.
Is it a bug from MS?
--
Regards
Hardy
Re: XhtmlTextWriter writes table and attributes problem
am 29.01.2008 03:46:46 von Coskun
Hi,
Can you try the following code please.
xWriter.RenderBeginTag(HtmlTextWriterTag.Img);
xWriter.AddAttribute(HtmlTextWriterAttribute.Src, "a.gif");
xWriter.AddAttribute(HtmlTextWriterAttribute.Border, "0");
xWriter.RenderEndTag();
xWriter.RenderBeginTag(HtmlTextWriterTag.Img);
xWriter.AddAttribute(HtmlTextWriterAttribute.Src, "a.gif");
xWriter.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, "0px");
xWriter.RenderEndTag();
xWriter.RenderBeginTag(HtmlTextWriterTag.Img);
xWriter.AddAttribute(HtmlTextWriterAttribute.Src, "a.gif");
xWriter.AddAttribute("borderwidth", "0");
xWriter.RenderEndTag();
xWriter.RenderBeginTag(HtmlTextWriterTag.Img);
xWriter.AddAttribute(HtmlTextWriterAttribute.Src, "a.gif");
xWriter.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, "0");
xWriter.RenderEndTag();
On Tue, 29 Jan 2008 04:03:28 +0200, Hardy Wang =
wrote:
> xWriter.AddAttribute(HtmlTextWriterAttribute.Src, "a.gif");
> xWriter.AddAttribute(HtmlTextWriterAttribute.Border, "0");
> xWriter.RenderBeginTag(HtmlTextWriterTag.Img);
> xWriter.RenderEndTag();
> Won't add border=3D"0" to img tag.
> xWriter.AddAttribute(HtmlTextWriterAttribute.Src, "a.gif");
> xWriter.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, "0px");
> xWriter.RenderBeginTag(HtmlTextWriterTag.Img);
> xWriter.RenderEndTag();
> Won't add border=3D"0" to img tag.
> xWriter.AddAttribute(HtmlTextWriterAttribute.Src, "a.gif");
> xWriter.AddAttribute("borderwidth", "0");
> xWriter.RenderBeginTag(HtmlTextWriterTag.Img);
> xWriter.RenderEndTag();
> Won't add border=3D"0" to img tag.
> xWriter.AddAttribute(HtmlTextWriterAttribute.Src, "a.gif");
> xWriter.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, "0");
> xWriter.RenderBeginTag(HtmlTextWriterTag.Img);
> xWriter.RenderEndTag();
> Won't add border=3D"0" to img tag.
-- =
All the best,
Coskun SUNALI
Microsoft MVP
http://sunali.com
http://propeople.dk