开发者

how to set the property background image of HTML body in skin file in Asp.Net?

how to set the property background image of HTML body in skin file in Asp.Net?

what I need is I need to change the background image开发者_高级运维 of my page like twitter... but by using skin file...


You don't set that property in the Skin file but in the Style File

in your style.css under your Theme folder inside App_Themes write the property

body {
    background: url(images/path.png) repeat 0 0;
}


I'm afraid Skin files are for native Asp.net Controls.

One alternative is to generate your CSS on the fly (or have it already made) and load that CSS for the user in the Code-Behind. Simply place this in the Head element of your aspx page/masterpage:

<link id="Custom_StyleSheet" runat="server"
      rel="stylesheet" type="text/css" href="" />

And add this to your Master Page (or regular Aspx page):

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    if (IsPostBack == false)
    {
        if (boolUseCustomStyleSheet ==  true)
        {
            //This is the relative path of your Css file.
            Custom_StyleSheet.Href  = sColorCssPath;
        }
    }
}



If you need more fine grain control, you can make <body> a server-side control like so:

Change <body> to :

<body id="someBody" runat="server" >

Then add this to your code-behind:

protected void Page_Load(object sender, EventArgs e)
{
    someBody.Style.Add("background-color", "Silver");
}

I wouldn't recommend the latter approach, but you could have a list of styles to add based on individual user. If it's a finite list of styles, then I'd just create the CSS for each of them and then add them dynamically like in the earlier example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜