send <style> info from custom server asp element

安稳与你 提交于 2019-12-06 13:16:08

The this.Page.Header.Stylesheet.CreateStyleRule method lets you add styles to the <head>. However, the CSS attributes that you can specify are limited to those supported by the Style class. (You can derive your own class from Style if you need additional attributes.)

C# example:

protected override void OnPreRender(EventArgs e)
{
    base.OnPreRender(e);

    // Create a Style object for the body of the page.
    Style bodyStyle = new Style();

    bodyStyle.ForeColor = System.Drawing.Color.Blue;
    bodyStyle.BackColor = System.Drawing.Color.LightGray;

    // Add the style rule named bodyStyle to the header 
    // of the current page. The rule is for the body HTML element.
    this.Page.Header.StyleSheet.CreateStyleRule(bodyStyle, null, "body");
}

Derive from System.Web.UI.Control directly and override the Render method, instead of deriving from (what I assume is) System.Web.IO.WebControls.WebControl.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!