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 11 August 2004, 03:40 PM
  #1  
Fatman
Scooby Regular
Thread Starter
 
Fatman's Avatar
 
Join Date: Aug 2002
Posts: 2,390
Likes: 0
Received 0 Likes on 0 Posts
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?
Old 11 August 2004, 03:55 PM
  #2  
SCOSaltire
Scooby Regular
 
SCOSaltire's Avatar
 
Join Date: Mar 2001
Posts: 1,809
Likes: 0
Received 0 Likes on 0 Posts
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.
Old 11 August 2004, 03:56 PM
  #3  
SCOSaltire
Scooby Regular
 
SCOSaltire's Avatar
 
Join Date: Mar 2001
Posts: 1,809
Likes: 0
Received 0 Likes on 0 Posts
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
Old 11 August 2004, 04:13 PM
  #4  
Fatman
Scooby Regular
Thread Starter
 
Fatman's Avatar
 
Join Date: Aug 2002
Posts: 2,390
Likes: 0
Received 0 Likes on 0 Posts
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!
Old 11 August 2004, 04:22 PM
  #5  
SCOSaltire
Scooby Regular
 
SCOSaltire's Avatar
 
Join Date: Mar 2001
Posts: 1,809
Likes: 0
Received 0 Likes on 0 Posts
Default

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

no probs
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
KAS35RSTI
Subaru
27
04 November 2021 07:12 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
28
28 December 2015 11:07 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
12
18 November 2015 07:03 AM
InTurbo
Other Marques
20
08 October 2015 08:59 PM
Brzoza
Engine Management and ECU Remapping
1
02 October 2015 05:26 PM



Quick Reply: Question for ASP.NET developers



All times are GMT +1. The time now is 05:27 PM.