Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Question for ASP.NET developers

Thread Tools
 
Search this Thread
 
Old Aug 11, 2004 | 03:40 PM
  #1  
Fatman's Avatar
Fatman
Thread Starter
Scooby Regular
 
Joined: Aug 2002
Posts: 2,390
Likes: 0
Default Question for ASP.NET developers

I want to allow users of my site to choose what CSS file the site is rendered with. I'm assuming I'll be storing that preference in cookies (since not all visitors are registered in the dB) and also also assuming that I'll applying that preference page-wise in the header.

How can I pass that variable/string from the codebehind forward into the header of the .aspx page? I've tried a line such as...

<link href="<%= CSSpreferenceString %>" type=text/css rel=stylesheet>

...but Visual Studio complains about this and highlights the <% and %> in yellow. Is there anything special about the declaration of things you want to use in the .aspx instead of the codebehind?
Reply
Old Aug 11, 2004 | 03:55 PM
  #2  
SCOSaltire's Avatar
SCOSaltire
Scooby Regular
 
Joined: Mar 2001
Posts: 1,809
Likes: 0
Default

in the head put

<link id="selStylesheet" rel="styleSheet" runat="server"></link>

in the codebehind

Protected selStylesheet As System.Web.UI.HtmlControls.HtmlGenericControl

in the Page.Load event put

Private Sub Page_Load (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Get cookie value
selStylesheet.Attributes.Add("href", thevalue)
End Sub

u could put select case statements so that the selection stored inthe cookie isnt the url to the stylesheet but more friendly, and get the url from whereever... from constants in the code, or from appSettings in the web.config

Thats one way of doing it.
Reply
Old Aug 11, 2004 | 03:56 PM
  #3  
SCOSaltire's Avatar
SCOSaltire
Scooby Regular
 
Joined: Mar 2001
Posts: 1,809
Likes: 0
Default

the trick here is the Runat="server"

and dimming a usuable UI object in the codebehind.

means u have access to it via code
Reply
Old Aug 11, 2004 | 04:13 PM
  #4  
Fatman's Avatar
Fatman
Thread Starter
Scooby Regular
 
Joined: Aug 2002
Posts: 2,390
Likes: 0
Default

Thanks SCOSaltire. I posted the same question on another Forum and a poster over there suggested using a Literal control. Probably a "six of one, half a dozen of another" situation! Thanks, though -- I didn't know the System.Web.UI.HtmlControls.HtmlGenericControl thing existed!
Reply
Old Aug 11, 2004 | 04:22 PM
  #5  
SCOSaltire's Avatar
SCOSaltire
Scooby Regular
 
Joined: Mar 2001
Posts: 1,809
Likes: 0
Default

aye, that generic control is often used in creating User Controls

no probs
Reply
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
KAS35RSTI
Subaru
27
Nov 4, 2021 07:12 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
28
Dec 28, 2015 11:07 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
12
Nov 18, 2015 07:03 AM
InTurbo
Other Marques
20
Oct 8, 2015 08:59 PM
Brzoza
Engine Management and ECU Remapping
1
Oct 2, 2015 05:26 PM




All times are GMT +1. The time now is 04:42 AM.