Solved

ASP.net 2.0 embedding a Style sheet header!

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now