473,657 Members | 2,667 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Dynamically Link CSS file to an ASPX Page?

Rather than hard-coding a reference to a css file in the HEAD of an aspx
page, like this...
<link rel="stylesheet " href="../css/admin.css" type="text/css">

How can I dynamically specify the particular css file to which the aspx page
is to link at runtime?

Thanks.
Nov 18 '05 #1
1 1546

"Jeremy" <JA*@2.com> wrote in message
news:Oc******** ******@TK2MSFTN GP11.phx.gbl...
Rather than hard-coding a reference to a css file in the HEAD of an aspx
page, like this...
<link rel="stylesheet " href="../css/admin.css" type="text/css">

How can I dynamically specify the particular css file to which the aspx page is to link at runtime?


You could do in the same way we did for classic ASP...
<link rel="stylesheet " type="text/css"
href='css/<%=Session("css stylesheet")%>. css' >

Or you might prefer a purer ASP.Net model...
Insert a literal into the <head> of your HTML...
<asp:literal id="Literal1" runat="server"> </asp:literal>

and then fill it in the Page_Load event...
Literal1.Text = String.Format(" <link rel=""styleshee t"" type=""text/css""
src=""{0}"" />", myCssDoc)

Brian Lowe
---------@
Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2074
by: Amir Eshterayeh | last post by:
Dear Friends I need to change the css file of my aspx files dynamically so users can choose their css file names and when page loads, it read css file name from database. I try to use response.write to write this way: Dim i As Integer = 1 If i = 1 Then Response.Write("<LINK href=""Stylesone.css"" type=""text/css"" rel=""stylesheet"">") Response.Write("<script language =""javascript"" src = ""testone.js"">
6
2433
by: John Ruiz | last post by:
Greetings, I originally posted this to microsoft.public.dotnet.framework.aspnet.datagridcontrol two weeks ago, but no one was able to answer. I am unable to dynamically add columns to a DataGrid in a web user control (.ascx) I am creating. This applies to VS.NET 2003 / Framework 1.1.
0
946
by: Bernie V | last post by:
Hello group, I'm working on a site with some newsheadlines. This is the idea: On the site there are some news headlines. Like: 20/01/2004
4
1802
by: Robert | last post by:
Are there any other ways to dynamically apply CSS styling to a page (without using inline CSS)? I'm sure I could dynamically generate a new and uniquely named CSS file "on the fly" when users log in, and then dynamically associate that css file with the requested pages - but I'm looking for something much simpler and with better runtime performance. Here's what I'm after. I plan to let users save various preferences between sessions....
12
2238
by: Wardeaux | last post by:
All, Wanting to find a way to create web pages to add to my website without having to recompile the codebehind everytime I want to add a new one... Here's the deal: I have a web app that takes work orders for 7 different items, each item gets 1 page for input specs. All works well. I want to add a new item. I do not want to recompile and redistribute my app everytime just to add a new input page. Can ASPX resources be compiled into a...
2
2505
by: Steve Franks | last post by:
What is the proper/best way to dynamically change the HTML written out to the browser based on the value from a variable in a code behind page? For instance, I have test.aspx.vb as a code behind page. In this code behind's Page_Load event which sets a boolean called useAlternateStyle to true or false based on business logic. Now from my main page (test.aspx) I want to either write out HTML that sets the style sheet to "mainStyle.css"...
9
7035
by: netasp | last post by:
hi all, how can I populate one aspx form when page is loading based on page ID? for example: loading page A (to search for VB code) would display labels and texboxes, dropdown lists all related to VB, plus the address bar would show something like this: www.somethinghere?id=3 and if you change number 3 from the address bar to (for example) 34 or 71 you would get different page with the same formatting like I.e: www.somethinghere?id=34...
6
2550
by: _Who | last post by:
I use the code below to change to a style sheet that has: body { ....
7
6651
by: RichB | last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am trying to add a tabbed control to the page. I have no problems within the aspx file, and can dynamically manipulate a tabcontainer which has 1 panel already, however I want to try create the TabPanels dynamically. I followed the advice here: http://www.asp.net/learn/ajax-videos/video-156.aspx (3rd comment - Joe Stagner)
0
8402
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8315
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8829
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8508
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5633
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4164
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2733
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.