[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webcontrols

How to apply style attributes to html elements generated by a custom control

Earl777

1/22/2003 7:42:00 PM

Objective
To be able to set the styles to serveral elements that my control renders by
using self contained style attributes.

Issue
I have created a custom control that generates a row and cells and I would
like set default self contained style attributes to these elements as well
as let the user of the control override these style attributes

Notes
Right now I pass the control the name and of an externally defined CSS
style for the row Class=, cell Class=, row OnMouseOver ClassName=, cell
OnMouseOver ClassName= properties. This works fine but I would like to set
self contained styles that can be set by the user to override the defaults.

Can I somehow create a Style s = new Style, set the style attribues, and
then apply them to a table row or cell?
How would this be done? I know I can expose some of the properties of the
Style object if I can figure out how to apply them to an html element.



Is there an artical or resource material on how this is done? I have 2 books
on Custom Controls but can not seem to find this exact issue being
addressed.

My current rendering code is listed below

Thanks for your help

Earl


protected override void RenderContents(HtmlTextWriter writer)
{
writer.AddAttribute("class",RowStyle);
writer.AddAttribute("OnMouseOver","this.className='"+ RowOverStyle + "'");
writer.AddAttribute("OnMouseOut","this.className='"+ RowStyle + "'");
writer.AddAttribute(HtmlTextWriterAttribute.Onclick,
Page.GetPostBackClientHyperlink(this, String.Empty));
writer.AddAttribute(HtmlTextWriterAttribute.Name, this.UniqueID);
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.RenderEndTag();
writer.AddAttribute("class",CellStyle);
writer.AddAttribute("OnMouseOver","this.className='"+ CellOverStyle + "'");
writer.AddAttribute("OnMouseOut","this.className='"+ CellStyle + "'");
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.Write(Text);
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.RenderEndTag();
writer.RenderEndTag();
}