1

I have the following c# code in my control's RenderContents method. How can I add the style/class that is in external css file?

output.AddAttribute(HtmlTextWriterAttribute.Border, "0");
output.AddAttribute(HtmlTextWriterAttribute.Width, "100%");
output.RenderBeginTag(HtmlTextWriterTag.Table);
output.RenderBeginTag(HtmlTextWriterTag.Tbody);
output.RenderBeginTag(HtmlTextWriterTag.Tr);
//Here -> Need to add some style from external stylesheet.css file
output.RenderBeginTag(HtmlTextWriterTag.Td);
rblLoadSelection.RenderControl(output);
output.RenderEndTag(); //Td
output.RenderEndTag(); //Tr
output.RenderEndTag(); //Tbody
output.RenderEndTag(); //Table
Sri Reddy
  • 6,832
  • 20
  • 70
  • 112

2 Answers2

2

You shouldn't reference an external stylesheet between a td and tr. The best place to put it is in the head tag of your document.

Based on your comments, if you just need to add a class to td, do this:

output.AddAttribute(HtmlTextWriterAttribute.Class, "myclass");
Keltex
  • 26,220
  • 11
  • 79
  • 111
1

I dont think you can include external CSS (without including it in head and use classes) or do it inline like this:

output.AddStyleAttribute(HtmlTextWriterStyle.Color, "#000000");
output.RenderBeginTag(HtmlTextWriterTag.Td);
janhartmann
  • 14,713
  • 15
  • 82
  • 138