Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.net 2.0 embedding a Style sheet header!

Posted on 2008-06-12
3
Medium Priority
?
262 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Accepted Solution

by:
Dustin Hopkins earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

636 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