Solved

ASP.net 2.0 embedding a Style sheet header!

Posted on 2008-06-12
3
257 Views
Last Modified: 2013-11-26
I need to add code like the following to the header programmatically using asp.net 2.0:
<STYLE TYPE="text/css">
<!--
      BODY      {background: #FFFFD8;
             margin-top: 20}
-->
</STYLE>
Another note: the header code is being grabbed dynamically from a sql server based on whatever the user has stored.
Thanks, Chris.
0
Comment
Question by:jumpstart0321
3 Comments
 
LVL 14

Accepted Solution

by:
Dustin Hopkins earned 500 total points
ID: 21776182
you could put something like this in the page load
 Dim css As String = "BODY {background-color: #FFFFD8; margin-top: 20}" 'Load css from db
        Dim myheader As HtmlHead = Page.Header
        If (Not css = Nothing And css.Length > 0) Then
            Dim litcss As Literal = New Literal()
            litcss.Text = "<style type='text/css'>" & css & "</style>"
            myHeader.Controls.Add(litcss)
        End If

Open in new window

0
 
LVL 21

Expert Comment

by:naspinski
ID: 21776184
I would recommend using a masterpage with a

    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>

In the head, then in your page (which uses the master)

You simply include:

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
  <style type="text/css">
    <asp:Literal ID="style" runat="server" />
  </style>
</asp:Content>

Then you can manipulate style behind the scenes.

Or if you prefer, you could just use:

<style type="text/css">
    <asp:Literal ID="style" runat="server" />
</style>

inside your head for each page (the materpage would be to reduce redundancy)
0
 

Author Closing Comment

by:jumpstart0321
ID: 31466827
Thanks man :)
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question