Solved

ASP.net 2.0 embedding a Style sheet header!

Posted on 2008-06-12
3
255 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

778 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